47472023-03-31 10:52:05AGergoLeggyorsabb pénzkeresés (50)cpp17Accepted 50/50193ms5408 KiB
#include <bits/stdc++.h>

using namespace std;


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

    int napszam,penz;
    cin >> napszam >> penz;
    int maxlen = napszam, len, sum;

    vector<int> napi(napszam);

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

    for(int i = 0; i < napszam; i++)
    {
        len = 1;
        sum = napi[i];

        while(len < maxlen && sum < penz)
        {

            if(len + i > napszam)
            {
                break;
            }

            sum += napi[i + len];
            len++;
        }
        //cout << sum << " " << i << " " << len << "\n";

        if(len + i > napszam)
        {
            break;
        }
        if(len < maxlen)
        {
            maxlen = len;
        }
    }
    cout << maxlen;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2104 KiB
2Accepted0/0184ms2964 KiB
3Accepted2/23ms2276 KiB
4Accepted2/23ms2452 KiB
5Accepted2/22ms2536 KiB
6Accepted2/26ms2580 KiB
7Accepted2/214ms2728 KiB
8Accepted2/217ms2916 KiB
9Accepted2/26ms3112 KiB
10Accepted2/216ms3160 KiB
11Accepted2/212ms4092 KiB
12Accepted2/2193ms4216 KiB
13Accepted2/2133ms4440 KiB
14Accepted2/243ms4392 KiB
15Accepted2/2128ms4192 KiB
16Accepted2/241ms4252 KiB
17Accepted2/237ms4256 KiB
18Accepted2/257ms4380 KiB
19Accepted2/2164ms4828 KiB
20Accepted2/2107ms5012 KiB
21Accepted2/264ms4896 KiB
22Accepted2/290ms5096 KiB
23Accepted2/2186ms5324 KiB
24Accepted2/286ms5204 KiB
25Accepted2/2112ms5204 KiB
26Accepted2/261ms5408 KiB
27Accepted2/259ms5408 KiB