fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int LIM = 60009;
  5.  
  6. int n;
  7. int a[LIM], s[LIM];
  8.  
  9. void read() {
  10. cin >> n;
  11. a[0] = 0;
  12. s[0] = 0;
  13.  
  14. for (int i=1; i<=n; i++) {
  15. cin >> a[i];
  16. s[i] = s[i-1] + a[i];
  17. }
  18. }
  19.  
  20. void process() {
  21. int l=0, r=0;
  22.  
  23. for (int i = 1; i <= n; i++) {
  24. for (int j = 1; j <= i; j++)
  25. if (s[i] > s[j-1]) {
  26. if (r-l < i-j) {
  27. r = i;
  28. l = j;
  29. }
  30. break;
  31. }
  32. }
  33. cout << l << " " << r << endl;
  34. }
  35.  
  36. int main() {
  37. read();
  38. process();
  39. }
Success #stdin #stdout 0s 15712KB
stdin
10
-5 -2 -3 4 -6 7 -8 9 -1 -20
stdout
2 8