92892024-02-20 08:06:13AGergoLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5014ms8804 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(0);

    int nap;
    int kell;
    cin >> nap >> kell;
    vector<int> fizetes(nap);

    for(int i = 0; i < nap; i++)
    {
        cin >> fizetes[i];
    }

    int ST=0,EN=0,minLen=nap+1,c=fizetes[0];

    //cout << c << " " << ST << "-" << EN << ":" << minLen << endl;

    while(EN < nap)
    {

        if(c>=kell)
        {
            if(EN-ST+1 < minLen)
            {
                minLen = EN-ST+1;
            }
            c-= fizetes[ST];
            ST++;
        }
        else
        {
            EN++;
            c+= fizetes[EN];
        }
        //cout << c << " " << ST << "-" << EN << ":" << minLen << endl;
    }

    cout << minLen;

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/014ms3228 KiB
3Accepted2/23ms2840 KiB
4Accepted2/23ms2920 KiB
5Accepted2/23ms3052 KiB
6Accepted2/24ms3196 KiB
7Accepted2/24ms3448 KiB
8Accepted2/24ms3544 KiB
9Accepted2/24ms3676 KiB
10Accepted2/24ms3664 KiB
11Accepted2/214ms5000 KiB
12Accepted2/214ms5564 KiB
13Accepted2/214ms6172 KiB
14Accepted2/214ms6768 KiB
15Accepted2/214ms7360 KiB
16Accepted2/214ms7836 KiB
17Accepted2/214ms8316 KiB
18Accepted2/214ms8784 KiB
19Accepted2/214ms8744 KiB
20Accepted2/214ms8804 KiB
21Accepted2/214ms8752 KiB
22Accepted2/214ms8652 KiB
23Accepted2/214ms8656 KiB
24Accepted2/214ms8656 KiB
25Accepted2/214ms8800 KiB
26Accepted2/214ms8756 KiB
27Accepted2/214ms8660 KiB