Advertisement
TimxAG

Untitled

Sep 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 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;
  6. cin >> n;
  7. int a[n+1];a[1]=0;
  8.  
  9. // cout << a[1] << " ";
  10. for (i=2;i<=n+1;i++)
  11. {
  12. cin >> k;
  13. a[i]=a[i-1]+k;
  14. // cout << a[i] << " ";
  15. }
  16. cout << endl;
  17. for (i=1;i<=n+1;i++)
  18. {
  19. for (j=i;j<=n+1;j++)
  20. {
  21. // cout << maxx << endl;
  22. // cout << i << " " << j << " " << a[i] << " " << a[j] << " " << (a[j]-a[i]) << " ";
  23. if ((a[j]-a[i])>maxx) {maxx = (a[j]-a[i]); maxj=j-1; maxi=i;}
  24. // cout << maxx << endl;
  25. }
  26.  
  27. }
  28. if (n == 1) cout << maxi << " " << maxi;
  29. else if (maxi == maxj) cout << maxi << " " << maxi;
  30. else cout << maxi << " " << maxj;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement