70772023-12-29 19:39:50MagyarKendeSZLGLeghosszabb nyaralás (75 pont)cpp17Accepted 75/7513ms6920 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N, P;
    cin >> N >> P;
    vector<int> v(N);
    cinv(v);

    int result = 0, curr_sum = v[0]; 

    for (int l = 0, r = 1; r <= N; r++) {

        while (P < curr_sum && l < r - 1) {
            curr_sum -= v[l];
            l++;
        }

        if (curr_sum <= P) {
            result = max(result, r - l);
        }

        if (r < N) {
            curr_sum += v[r];
        }
    }

    cout << result;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1956 KiB
2Accepted0/013ms3408 KiB
3Accepted3/33ms2820 KiB
4Accepted3/33ms3032 KiB
5Accepted3/33ms3148 KiB
6Accepted3/33ms3356 KiB
7Accepted3/33ms3436 KiB
8Accepted4/43ms3664 KiB
9Accepted4/43ms3712 KiB
10Accepted5/53ms3836 KiB
11Accepted5/54ms4236 KiB
12Accepted5/54ms4056 KiB
13Accepted7/79ms4856 KiB
14Accepted7/712ms5340 KiB
15Accepted7/713ms5860 KiB
16Accepted8/813ms6200 KiB
17Accepted8/813ms6920 KiB