HDU 5280 Senior ' s Array maximum range and

Source: Internet
Author: User

Test instructions: Given n number, it is required to change one of the number to p, the maximum interval and the number of changes can be.





Water problem. Enumerate each interval, if the interval is not modified (that is, modify the number outside the interval), then for that interval and, if the interval to be modified, because it must be modified, so it is necessary to change the minimum number to P can guarantee the last and largest interval, so compare the larger of the two schemes. For each interval removed the larger, then take the total maximum. Note that a trick, when enumerated to the entire interval, is necessary to modify a number, so this largest interval has only one scheme. 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;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5280 Senior ' s Array maximum range 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.