fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. int n, a[1000009], res = 0, p = 1000009;
  4. pair<long long, int> f[1000009];
  5. int main()
  6. {
  7. ios::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10. if(fopen("lsm.inp","r"))
  11. {
  12. freopen("lsm.inp","r",stdin);
  13. freopen("lsm.out","w",stdout);
  14. }
  15. cin >> n;
  16. f[0].first = 0;
  17. f[0].second = 0;
  18. for(int i=1; i<=n; i++)
  19. {
  20. cin >> a[i];
  21. f[i].first = f[i - 1].first + a[i];
  22. f[i].second = i;
  23. }
  24.  
  25. sort(f, f + n + 1);
  26.  
  27. for(int i=0; i<=n; i++)
  28. {
  29. res = max(res, f[i].second - p);
  30. p = min(p, f[i].second);
  31. }
  32. cout << res;
  33. return 0 ;
  34. }
  35.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty