Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef long long ll;
- const ld eps = 0.000000001;
- const ld pi = 3.14159265358979323;
- int main(int argc, char **argv)
- {
- ios_base::sync_with_stdio(false);
- #ifndef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif // LOCAL
- int n;
- cin >> n;
- vector<ll> a(n);
- for(auto &i : a) {
- cin >> i;
- }
- ll ans = a[0], sum = 0;
- ll l = 0, r = 0, pred_l = -1;
- for(int i = 0; i < a.size(); ++i) {
- sum += a[i];
- if(sum > ans) {
- ans = sum;
- l = pred_l + 1;
- r = i;
- }
- if(sum < 0) {
- sum = 0;
- pred_l = r;
- }
- }
- cout << l + 1 << " " << r + 1 << " " << ans << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment