1212021-01-16 11:50:16Valaki2Leghosszabb nyaralás (75 pont)cpp11Time limit exceeded 35/75294ms1900 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) cin >> v[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 && sum + v[r+1] <= k) {
            ++r;
            sum += v[r];
        }
        //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";*/
    int maxi = 0;
    for(int i = 0; i < n - 1; ++i) {
        long long sum = v[i];
        for(int j = i+1; j < n; ++j) {
            sum += v[j];
            if(sum <= k) maxi = max(maxi, j - i + 1);
        }
    }
    cout << maxi << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base35/75
1Accepted0/01ms1740 KiB
2Time limit exceeded0/0294ms1304 KiB
3Wrong answer0/31ms1824 KiB
4Accepted3/31ms1720 KiB
5Accepted3/31ms1824 KiB
6Accepted3/31ms1824 KiB
7Accepted3/31ms1824 KiB
8Accepted4/41ms1824 KiB
9Accepted4/41ms1780 KiB
10Accepted5/52ms1828 KiB
11Accepted5/550ms1892 KiB
12Accepted5/548ms1900 KiB
13Time limit exceeded0/7284ms1356 KiB
14Time limit exceeded0/7293ms1356 KiB
15Time limit exceeded0/7293ms1356 KiB
16Time limit exceeded0/8291ms1484 KiB
17Time limit exceeded0/8293ms1488 KiB