41442023-03-15 14:02:28gittyLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5032ms4592 KiB
#include <iostream>
#include <queue>
#include <fstream>
using namespace std;

int main()
{
    //ifstream cin("in.txt");
    queue <long long int> pieces;
    long long int n, p;
    cin>>n>>p;
    long long int x;
    long long int s=0;
    long long int minl=100000;
    for(int i = 1; i<=n; i++)
    {
        cin>>x;
        s+=x;
        pieces.push(x);
        if(s>=p)
        {
            while(s-pieces.front() >=p && !pieces.empty())
            {
                s-=pieces.front();
                pieces.pop();
            }
            if(pieces.size() < minl)
            {
                //cout<<pieces.size()<<"\n";
                minl = pieces.size();
            }
        }
    }
    cout<<minl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1684 KiB
2Accepted0/032ms1936 KiB
3Accepted2/23ms2140 KiB
4Accepted2/23ms2304 KiB
5Accepted2/23ms2512 KiB
6Accepted2/24ms2696 KiB
7Accepted2/26ms2900 KiB
8Accepted2/26ms3116 KiB
9Accepted2/26ms3192 KiB
10Accepted2/26ms3332 KiB
11Accepted2/232ms3524 KiB
12Accepted2/232ms3784 KiB
13Accepted2/232ms3832 KiB
14Accepted2/232ms3824 KiB
15Accepted2/232ms3960 KiB
16Accepted2/232ms4036 KiB
17Accepted2/232ms4272 KiB
18Accepted2/232ms4280 KiB
19Accepted2/232ms4284 KiB
20Accepted2/232ms4356 KiB
21Accepted2/232ms4356 KiB
22Accepted2/232ms4592 KiB
23Accepted2/232ms4580 KiB
24Accepted2/232ms4464 KiB
25Accepted2/232ms4464 KiB
26Accepted2/232ms4456 KiB
27Accepted2/232ms4460 KiB