fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define yes cout<<"YES\n";
  6. #define no cout<<"NO\n";
  7. const int N=3e5+7;
  8. ll T = 1, a[N], b[N];
  9. void solve()
  10. {
  11. ll n, m;
  12.  
  13. cin >> n >> m;
  14.  
  15. for(int i = 1; i <= n; i++)
  16. cin >> a[i];
  17.  
  18. int mn = n + 1, l = 1;
  19. ll sum = 0;
  20.  
  21. for(int r = 1; r <= n; r++){
  22. sum += a[r];
  23.  
  24. while(l <= r && sum - a[l] >= m)
  25. sum -= a[l], l++;
  26.  
  27. if(sum >= m)
  28. mn = min(mn, r - l + 1);
  29. }
  30. cout << mn;
  31. }
  32. int main()
  33. {
  34. ios::sync_with_stdio(NULL);
  35. cin.tie(0);
  36. cout.tie(0);
  37.  
  38. // freopen("","r", stdin);
  39. // freopen("","w", stdout);
  40. // cin>>T;
  41. while(T--)
  42. solve();
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5712KB
stdin
7 20
2 6 4 3 6 8 9
stdout
3