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,mina=INT_MAX,maxa=INT_MIN;
- scanf("%d",&n);
- int a[n+1];a[1]=0;
- // cout << a[1] << " ";
- for (i=2;i<=n+1;i++)
- {
- scanf("%d",&k);
- a[i]=a[i-1]+k;
- if (a[i]<mina) mina=a[i];
- if (a[i]>maxa) maxa=a[i];
- // cout << a[i] << " ";
- }
- for (i=1;i<=n+1;i++)
- {
- if (a[i]>(maxa+mina)/2) continue; else
- 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) printf("%d %d",maxi,maxi);
- else if (maxi == maxj) printf("%d %d",maxi,maxi);
- else printf("%d %d",maxi,maxj);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement