Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,i,j,maxx=-INT_MAX,maxj=1,maxi=1,k;
- cin >> n;
- int a[n+1];a[1]=0;
- // cout << a[1] << " ";
- for (i=2;i<=n+1;i++)
- {
- cin >> k;
- a[i]=a[i-1]+k;
- // cout << a[i] << " ";
- }
- cout << endl;
- for (i=1;i<=n+1;i++)
- {
- for (j=i;j<=n+1;j++)
- {
- // cout << maxx << endl;
- // cout << i << " " << j << " " << a[i] << " " << a[j] << " " << (a[j]-a[i]) << " ";
- if ((a[j]-a[i])>maxx) {maxx = (a[j]-a[i]); maxj=j-1; maxi=i;}
- // cout << maxx << endl;
- }
- }
- if (n == 1) cout << maxi << " " << maxi;
- else if (maxi == maxj) cout << maxi << " " << maxi;
- else cout << maxi << " " << maxj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement