fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e6+7;
  4. int n,res(0);
  5. int a[maxn];
  6. bool check(int l)
  7. {
  8. for(int i=l;i<=n;i++)
  9. for(int j=l;j<=i;j++)
  10. if(a[i]-a[i-j]> 0)
  11. return true;
  12. return false;
  13. }
  14. int main()
  15. {
  16. cin >> n;
  17. for(int i=1;i<=n;i++)
  18. {
  19. cin >> a[i];
  20. a[i]=a[i-1]+a[i];
  21. }
  22.  
  23. int d=1, c=n;
  24. while(d<=c)
  25. {
  26. int g = (d+c)/2;
  27. if(check(g))
  28. {
  29. res = max(res,g);
  30. d=g+1;
  31. }
  32. else
  33. c=g-1;
  34. }
  35. cout << res;
  36. }
  37.  
Success #stdin #stdout 0.01s 5420KB
stdin
10
-5 -2 -3 4 -6 7 -8 9 -1 -20
stdout
7