Advertisement
TimxAG

Untitled

Sep 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,i,j,maxx=-INT_MAX,maxj=1,maxi=1,k,mina=INT_MAX,maxa=INT_MIN;
  6. scanf("%d",&n);
  7. int a[n+1];a[1]=0;
  8.  
  9. // cout << a[1] << " ";
  10. for (i=2;i<=n+1;i++)
  11. {
  12. scanf("%d",&k);
  13. a[i]=a[i-1]+k;
  14. if (a[i]<mina) mina=a[i];
  15. if (a[i]>maxa) maxa=a[i];
  16. // cout << a[i] << " ";
  17. }
  18. for (i=1;i<=n+1;i++)
  19. {
  20. if (a[i]>(maxa+mina)/2) continue; else
  21. for (j=i;j<=n+1;j++)
  22. {
  23. // cout << maxx << endl;
  24. // cout << i << " " << j << " " << a[i] << " " << a[j] << " " << (a[j]-a[i]) << " ";
  25. if ((a[j]-a[i])>maxx) {maxx = (a[j]-a[i]); maxj=j-1; maxi=i;}
  26. // cout << maxx << endl;
  27. }
  28.  
  29. }
  30. if (n == 1) printf("%d %d",maxi,maxi);
  31. else if (maxi == maxj) printf("%d %d",maxi,maxi);
  32. else printf("%d %d",maxi,maxj);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement