84382024-01-16 09:57:41GervidLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5034ms5384 KiB
#include <iostream>
#include <vector>
#include <limits.h>

using namespace std;

int main()
{
    int n, p, i, j;
    cin >> n >> p;

    vector<int> days(n);
    
    for (i = 0; i < n; i++)
    {
        cin >> days[i];
    }

    int current = days[0], out = INT_MAX;
    i = 0, j = 0;

    while (j < n)
    {
        while (current >= p)
        {
            if (out > j - i + 1 && current >= p && j < n)
            {
                out = j - i + 1;
            }

            current -= days[i];
            i++;
        
            if (out > j - i + 1 && current >= p && j < n)
            {
                out = j - i + 1;
            }
        }

        while (current < p)
        {
            j++;

            if (j >= n)
            {
                break;
            }

            current += days[j];
        }

    }

    cout << out;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/034ms2640 KiB
3Accepted2/23ms2416 KiB
4Accepted2/23ms2444 KiB
5Accepted2/23ms2584 KiB
6Accepted2/26ms2712 KiB
7Accepted2/26ms2792 KiB
8Accepted2/26ms2900 KiB
9Accepted2/26ms3172 KiB
10Accepted2/26ms3248 KiB
11Accepted2/234ms3912 KiB
12Accepted2/234ms3796 KiB
13Accepted2/234ms4196 KiB
14Accepted2/234ms4152 KiB
15Accepted2/234ms4224 KiB
16Accepted2/234ms4604 KiB
17Accepted2/234ms4684 KiB
18Accepted2/234ms4640 KiB
19Accepted2/234ms4772 KiB
20Accepted2/234ms4968 KiB
21Accepted2/234ms5016 KiB
22Accepted2/234ms5016 KiB
23Accepted2/234ms5012 KiB
24Accepted2/234ms5144 KiB
25Accepted2/234ms5384 KiB
26Accepted2/234ms5336 KiB
27Accepted2/234ms5228 KiB