40552023-03-11 12:13:22gittyLeggyorsabb pénzkeresés (50)cpp17Wrong answer 0/5030ms5636 KiB
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;

int main()
{
   // ifstream f("in.txt");
    vector <int> pieces;
    int n, p;
    cin>>n>>p;
    //f>>n>>p;
    int x;
    int s;
    int minl=100000;
   // cout<<n<<" "<<p;
    for(int i =1; i<=n; i++)
    {
        cin>>x;
        if(s+x < p)
        {
            s+=x;
            pieces.push_back(x);
        }
        else
        {
            while(s-*pieces.begin() > p)
            {
                s-=*pieces.begin();
                pieces.erase(pieces.begin());
            }
            if(pieces.size() < minl)
            {
                //cout<<pieces.size()<<" ";
                minl = pieces.size();
            }
        }
    }
    cout<<minl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1944 KiB
2Wrong answer0/030ms3312 KiB
3Runtime error0/23ms2488 KiB
4Wrong answer0/23ms2580 KiB
5Runtime error0/23ms2516 KiB
6Runtime error0/23ms2776 KiB
7Runtime error0/23ms2836 KiB
8Wrong answer0/24ms2976 KiB
9Runtime error0/23ms3096 KiB
10Wrong answer0/24ms3184 KiB
11Wrong answer0/230ms4352 KiB
12Runtime error0/23ms3224 KiB
13Wrong answer0/230ms4504 KiB
14Runtime error0/23ms3684 KiB
15Runtime error0/23ms3964 KiB
16Runtime error0/23ms3924 KiB
17Runtime error0/23ms4048 KiB
18Runtime error0/23ms3984 KiB
19Wrong answer0/229ms5164 KiB
20Runtime error0/23ms4064 KiB
21Wrong answer0/230ms5252 KiB
22Wrong answer0/229ms4496 KiB
23Wrong answer0/230ms5548 KiB
24Wrong answer0/230ms5636 KiB
25Wrong answer0/230ms5628 KiB
26Wrong answer0/229ms5636 KiB
27Runtime error0/23ms4480 KiB