1172021-01-16 11:18:23Valaki2Leghosszabb nyaralás (75 pont)cpp14Wrong answer 72/7523ms4644 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int& i : v) cin >> i;
    int l = 0;
    int r = 0;
    long long sum = v[0];
    int maxi = 0, lans = -1, rans = -1;
    while(l < n) {
        if(r < n - 1) {
            if(v[r+1] > k) {
                l = r + 2;
                r = r + 2;
                if(r < n) {
                    sum = v[r];
                } else break;
            }
        }
        while(r < n - 1) {
            if(sum + v[r+1] <= k) {
                ++r;
                sum += v[r];
            } else break;
        }
        if(r-l+1>maxi){lans=l;rans=r;}
        maxi = max(r - l + 1, maxi);
        ++l;
        sum -= v[l-1];
    }
    //cout << lans+1 << " " << rans+1 << "\n";
    cout << maxi << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/01ms1736 KiB
2Accepted0/023ms2968 KiB
3Accepted3/31ms2224 KiB
4Accepted3/31ms2220 KiB
5Accepted3/31ms2236 KiB
6Accepted3/31ms2232 KiB
7Wrong answer0/31ms2240 KiB
8Accepted4/41ms2244 KiB
9Accepted4/41ms2248 KiB
10Accepted5/51ms2256 KiB
11Accepted5/53ms2292 KiB
12Accepted5/53ms2324 KiB
13Accepted7/717ms3192 KiB
14Accepted7/719ms3548 KiB
15Accepted7/723ms3916 KiB
16Accepted8/823ms4272 KiB
17Accepted8/823ms4644 KiB