levels and a list of rounds rounds, where rounds[j] = [l, r, val]. During a round, every cell from index l to r inclusive may be lowered by any whole amount from 0 to val, chosen separately for each cell.
Rounds are applied strictly in order. Find the smallest k ≥ 0 such that after the first k rounds the array can be made all zeros. If even all the rounds are not enough, return -1.levels=[3, 1, 2], rounds=[[0, 1, 2], [2, 2, 1], [0, 2, 1], [1, 2, 4]] → 3
After two rounds the cells can drop by at most [2, 2, 1], while cell 0 needs 3 and cell 2 needs 2. After the third round the budget [3, 3, 2] covers everything, so the answer is 3.
levels=[0, 0], rounds=[[0, 1, 1]] → 0
The array is already all zeros, so no rounds are needed.
levels=[5], rounds=[[0, 0, 2], [0, 0, 2]] → -1
Even both rounds together lower the cell by at most 4, which is not enough.
levels=[3, 1, 2], rounds=[[0, 1, 2], [2, 2, 1], [0, 2, 1], [1, 2, 4]]
3
Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.