There is an orchard with many trees and many fruits on it. Otherwise, the ripe fruit must be collected within two days. Given the number of trees in the orchard and the number of fruits on the tree, the upper limit that workers can collect each day is obtained to find the maximum value that can be collected after this time period.
It is easy to maintain a one-dimensional array of ans []. First, the data is stored in the struct, and then sorted in ascending order by the fruit maturity date ai. The fruit is preferentially included in ans [ai, add more to ans [ai + 1]. If it is greater than the upper limit, it is recorded as the upper limit. The sum of all elements in the array is the answer.
# Include
# Include
# Include # define MAX_N 3000 using namespace std; struct fruit {int x, y ;}; bool cmp (fruit a, fruit B) {return a. x
V) ans [a [I]. x] = v; else ans [a [I]. x] + = ans [a [I]. x-1] + a [I]. y-v; ans [a [I]. x-1] = v ;}} int Mans = 0; for (int I = 0; I <= maxi; I ++) Mans + = ans [I]; printf (% d, Mans); return 0 ;}