55832023-08-02 11:54:12TomaSajtLeghosszabb nyaralás (75 pont)cpp17Accepted 75/7512ms4456 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n, p;
  cin >> n >> p;

  vector<int> costs(n);
  for (auto& c : costs) cin >> c;

  int total_cost = 0;
  int best_length = 0;

  int l = 0;
  for (int r = 0; r < n; r++) {
    total_cost += costs[r];
    while (total_cost > p) {
      total_cost -= costs[l];
      l++;
    }
    best_length = max(best_length, r - l + 1);
  }

  cout << best_length;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1828 KiB
2Accepted0/012ms2708 KiB
3Accepted3/33ms2356 KiB
4Accepted3/32ms2568 KiB
5Accepted3/33ms2684 KiB
6Accepted3/32ms2768 KiB
7Accepted3/33ms2888 KiB
8Accepted4/43ms3008 KiB
9Accepted4/43ms3180 KiB
10Accepted5/53ms3272 KiB
11Accepted5/53ms3304 KiB
12Accepted5/53ms3364 KiB
13Accepted7/79ms4140 KiB
14Accepted7/710ms4228 KiB
15Accepted7/712ms4224 KiB
16Accepted8/812ms4372 KiB
17Accepted8/812ms4456 KiB