Test instructions: given n number. It is required to change one of the numbers to p to find the maximum interval and the number of changes.
Water problem. Enumerates each interval. Assuming that the interval does not change (that is, the number of changes outside the interval), then for the interval and, if the interval to be changed, because of the need to change, so it must be the smallest number of changes to P can guarantee the last and largest interval, so the larger of the two schemes. For each interval of the larger, then take the total of the largest number of people can. Note that a trick, when enumerated to the entire interval, is required to change a number. So the biggest of this range is just one solution.
The interval of the 1~i is preprocessed and the minimum and interval of each interval are maintained.
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string > #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map > #include <set>using namespace std;const int MAX = 1005;const int INF = 1e9;int N;__int64 P, A[max];__int64 sum[m AX], smallest[max][max];void input () {scanf ("%d%i64d", &n, &p); for (int i = 1; I <= n; i++) scanf ("%i64d", &a[i]);} void Solve () {smallest[0][0] = INF; Sum[0] = 0; __int64 ans = P; for (int i = 1; I <= n; i++) sum[i] = Sum[i-1] + a[i]; for (int i = 1; I <= n; i++) {smallest[i][i] = A[i]; ans = max (ans, a[i]); for (int j = i + 1; j <= N; j + +) {Smallest[i][j] = min (smallest[i][j-1], a[j]); ans = max (ans, sum[j]-sum[i-1]-smallest[i][j] + P); if (i! = 1 | | J! = n) ans = max (ans, sum[j]-sum[i-1]); }} printf ("%i64d\n", ans);} int main () {int T; scanf ("%d", &t); while (t--) {input (); Solve (); } return 0;}
HDU 5280 senior& #39; s Array maximum interval and