fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. long long n,t;
  10. cin >>n >>t;
  11. long long in[1000000];
  12. long long in2[1000000];
  13. for (int i=1;i<=n;i++){
  14. cin >>in[i];
  15. in2[i]=in[i];
  16. }
  17. bool test=false;
  18.  
  19. for(int i=1;i<=n;i++){
  20. if(in2[i]<=t){
  21. test=true;
  22. }
  23. }
  24. if (test==false){
  25. cout << 0;
  26. return 0;
  27. }
  28. in[0]=0;
  29.  
  30. for (int i=1;i<=n;i++){
  31. in[i]=in[i-1]+in[i];
  32. }
  33. int b,e,mid,num,mx=0;
  34. //correct
  35.  
  36.  
  37. for(int a=1;a<n;a++){
  38. b=a;
  39. e=n;
  40. mid = (e+b)/2;
  41. while (b<e-1){
  42. if(in[mid]-in[a-1]>t){
  43. e=mid;
  44. }
  45. else if(in[mid]-in[a-1]<=t){
  46. b=mid;
  47. }
  48.  
  49. mid=(e+b)/2;
  50. }
  51. /*if(in[e]-in[a-1]<=t){
  52.   num=e;
  53.   }
  54.   else num=e-1;*/
  55. int num;
  56. if(in[e]-in[a-1]>t){
  57. num=b;
  58. }
  59. else if(in[e]-in[a-1]<=t){
  60. num=e;
  61. }
  62. int x1=num-a+1;
  63. mx=max(mx,x1);
  64. }
  65.  
  66. if (mx==0){
  67. for (int i=1;i<=n;i++){
  68. if (in2[i]<=t){
  69. cout << 1;
  70. return 0;
  71. }
  72. else {
  73. cout << 0;
  74. return 0;
  75. }
  76. }
  77. }
  78. cout <<mx;
  79. }
Success #stdin #stdout 0s 4504KB
stdin
10 1
4418 7528 8170 1736 1317 3205 8183 4995 8039 4708
stdout
Standard output is empty