17692022-12-02 21:26:35kdbLeghosszabb nyaralás (75 pont)cpp11Accepted 75/7510ms5164 KiB
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<int> vec;
    for (size_t i = 0; i < n; i++)
    {
        int a; cin >> a;
        vec.push_back(a);
    }
    int i = 0, j = 0, s = 0, m = -1;
    for ( j = 0; j < n; j++)
    {
        if (s + vec[j] <= k)
        {
            s += vec[j];
            i++;
        }
        else if (s != 0)
        {
            s -= vec[j - i];
            s += vec[j];
        }
        m = max(m, i);
    }
    cout << m << endl;
    return 0;
}
/*
8 10
3 6 4 2 3 7 2 9
-7
*/
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1828 KiB
2Accepted0/010ms3160 KiB
3Accepted3/32ms2120 KiB
4Accepted3/32ms2472 KiB
5Accepted3/32ms2536 KiB
6Accepted3/32ms2540 KiB
7Accepted3/32ms2664 KiB
8Accepted4/42ms2744 KiB
9Accepted4/42ms3024 KiB
10Accepted5/52ms2964 KiB
11Accepted5/53ms3412 KiB
12Accepted5/53ms3636 KiB
13Accepted7/79ms4664 KiB
14Accepted7/710ms4868 KiB
15Accepted7/710ms4904 KiB
16Accepted8/810ms4900 KiB
17Accepted8/810ms5164 KiB