Bzoj3544 [ontak2010] creative accounting

Source: Internet
Author: User

If you don't understand the question, you can't write a little like a human voice. I'll go...

 

The question is to find a range to maximize the Sigma AI mod m value.

So... Just get the prefix and get greedy.

 

First obtain the prefix and S of the number of I, and then update the solution with S.

It is also possible that the prefix and S1 of the previous section are the smallest and larger than S in mod m. Then the sum of M + S-S1 is used to update the solution.

 

 1 /************************************************************** 2     Problem: 3544 3     User: rausen 4     Language: C++ 5     Result: Accepted 6     Time:2056 ms 7     Memory:7012 kb 8 ****************************************************************/ 9  10 #include <cstdio>11 #include <algorithm>12 #include <set>13  14 using namespace std;15 typedef long long ll;16 int n;17 ll mod, s, a, ans, p;18 set <ll> S;19  20 inline ll read(){21     ll x = 0, sgn = 1;22     char ch = getchar();23     while (ch < ‘0‘ || ch > ‘9‘){24         if (ch == ‘-‘) sgn = -1;25         ch = getchar();26     }27     while (ch >= ‘0‘ && ch <= ‘9‘){28         x = (ll) x * 10 + ch - ‘0‘;29         ch = getchar();30     }31     return sgn * x;32 }33  34 int main(){35     scanf("%d", &n); mod = read();36     for (int i = 1; i <= n; ++i){37         a = read();38         if (a < 0) a += (abs(a / mod) + 1) * mod;39         s += a, s %= mod;40         ans = max(ans, s);41         if (S.upper_bound(s) != S.end()){42             p = *(S.upper_bound(s));43             ans = max(ans, (s + mod - p) % mod);44         }45         S.insert(s);46     }47     printf("%lld\n", ans);48     return 0;49 }
View code

(P.s. shamelessly I used set again ...)

Bzoj3544 [ontak2010] creative accounting

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.