HDU 5280 senior& #39; s Array maximum interval and

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.