55822023-08-02 11:49:37TomaSajtLeghosszabb nyaralás (75 pont)cpp17Wrong answer 61/7512ms6540 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, r = 0; // [l;r[

  while (r <= n) {
    if (total_cost < p) {
      total_cost += costs[r];
      r++;
    }
    else {
      total_cost -= costs[l];
      l++;
    }
    if (total_cost <= p) {
      best_length = max(best_length, r - l);
    }
  }

  cout << best_length;
}
SubtaskSumTestVerdictTimeMemory
base61/75
1Accepted0/03ms1828 KiB
2Accepted0/012ms3256 KiB
3Accepted3/33ms2668 KiB
4Wrong answer0/33ms2884 KiB
5Accepted3/32ms2968 KiB
6Accepted3/33ms2964 KiB
7Accepted3/33ms3180 KiB
8Wrong answer0/42ms3268 KiB
9Accepted4/43ms3508 KiB
10Accepted5/53ms3500 KiB
11Accepted5/53ms3792 KiB
12Accepted5/54ms3960 KiB
13Wrong answer0/79ms4876 KiB
14Accepted7/710ms5200 KiB
15Accepted7/712ms5624 KiB
16Accepted8/812ms6152 KiB
17Accepted8/812ms6540 KiB