84752024-01-17 11:45:10GervidVirágos rét (50 pont)cpp17Accepted 50/5021ms4240 KiB
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, k, i, j, leftp = 0;
    cin >> n >> k;

    vector<short> flowers(n);

    for (i = 0; i < n; i++)
    {
        cin >> flowers[i];
        leftp += flowers[i];
    }

    i = 0, j = 0;
    int pickable = flowers[0];
    leftp -= flowers[0];

    long out = 0;

    while (j < n)
    {
        while (pickable < k || i > j)
        {
            j++;

            if (j >= n)
            {
                cout << out;
                return 0;
            }

            pickable += flowers[j];
            leftp -= flowers[j];
        }

        out += leftp + 1;
        i++;
        pickable -= flowers[i];

        while (flowers[i] == 0)
        {
            i++;
            pickable -= flowers[i];
        }
    }

    cout << out;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2088 KiB
2Accepted0/03ms2220 KiB
3Accepted0/019ms2372 KiB
4Accepted2/23ms2248 KiB
5Accepted2/22ms2336 KiB
6Accepted2/22ms2332 KiB
7Accepted3/33ms2480 KiB
8Accepted3/33ms2632 KiB
9Accepted3/33ms2752 KiB
10Accepted2/23ms2744 KiB
11Accepted3/33ms2788 KiB
12Accepted2/23ms2784 KiB
13Accepted3/33ms3032 KiB
14Accepted2/218ms3440 KiB
15Accepted2/218ms3652 KiB
16Accepted3/321ms3608 KiB
17Accepted3/319ms3608 KiB
18Accepted3/320ms3804 KiB
19Accepted3/319ms3972 KiB
20Accepted3/319ms4080 KiB
21Accepted3/320ms4240 KiB
22Accepted3/319ms4180 KiB