Advertisement
a53

SecvMaxVal

a53
Oct 13th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n,v[200001];
  7. long long val;
  8. ifstream f("secvmaxval.in");
  9. f>>n>>val;
  10. for(int i=1;i<=n;++i)
  11. f>>v[i];
  12. f.close();
  13. long long S=0;
  14. int i=1,Lmax=0;
  15. for(int j=1;j<=n;++j)
  16. {
  17. S+= v[j];
  18. while(S>val)
  19. S-=v[i++];
  20. if(j-i+1>Lmax)
  21. Lmax=j-i+1;
  22. }
  23. ofstream g("secvmaxval.out");
  24. g<<Lmax;
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement