There is a system error in this task. Can anyone fix it?
z-trees
Can you explain the idea to solve this task.
Well the test cases are missing, nobody ever fixes them here.. Why even bother solving the problem? :(
Anyway, the solution converts the problem into a system of difference constraints, which can be solved using bellman ford. The trick that makes it solvable is to look at prefix-sums ( for example, let p[x] equal the number of trees from <-inf, x] ). Then if there are 5 trees in [x, y], you can say p[y]-p[x-1] = 5... and so on...
Anyway, the solution converts the problem into a system of difference constraints, which can be solved using bellman ford. The trick that makes it solvable is to look at prefix-sums ( for example, let p[x] equal the number of trees from <-inf, x] ). Then if there are 5 trees in [x, y], you can say p[y]-p[x-1] = 5... and so on...