fork download
  1. #include <bits/stdc++.h>
  2. #define task ""
  3. #define ff first
  4. #define ss second
  5. using namespace std;
  6. using ld = long double;
  7. using ull = unsigned long long;
  8. using ll = long long;
  9. using pll = pair <ll, ll>;
  10. using pii = pair <int, int>;
  11. const char el = '\n';
  12. const char sp = ' ';
  13. const ll inf = 1e9; //1e18;
  14. const ll maxN = 1e6 + 5;
  15.  
  16. int n;
  17. ll m, a[maxN];
  18.  
  19. int main ()
  20. {
  21. ios_base::sync_with_stdio(0);
  22. cin.tie(0);
  23. if (fopen(task".inp", "r"))
  24. {
  25. freopen(task".inp", "r", stdin);
  26. freopen(task".out", "w", stdout);
  27. }
  28. if (!(cin >> n >> m)) return 0;
  29. for (int i = 1; i <= n; ++i) cin >> a[i];
  30.  
  31. int min_k = 1, j = 1;
  32. ll current_sum = 0;
  33. for (int i = 1; i <= n; ++i)
  34. {
  35. while (j <= n && current_sum < m)
  36. {
  37. current_sum += a[j];
  38. j++;
  39. }
  40. if (current_sum >= m)
  41. {
  42. min_k = max(min_k, j - i);
  43. }
  44. else
  45. {
  46. min_k = max(min_k, n - i + 2);
  47. }
  48. current_sum -= a[i];
  49. }
  50. cout << min_k << el;
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty