66472023-12-15 09:25:58zsebiLeggyorsabb pénzkeresés (50)cpp17Wrong answer 46/5032ms4780 KiB
// leggyors_penzk.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long 
using namespace std;
ll n, k,p,v, ossz = 0;
int main()
{
    cin >> n >> p;
    vector<ll>x(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> x[i];
        if (x[i] >= p)
        {
            cout << "1";
            return 0;
        }
        ossz += x[i];
    }
    if (ossz < p)
    {
        cout << "0";
        return 0;
    }
    int i = 1;
    ossz = 0,k=1;
    while (i<=n && ossz<p)
    {
        ossz += x[i];
        ++i;
    }
    ll mini = 100001;
    while (i <= n)
    {
        ossz += x[i];
        if (ossz >p)
        {
            
            while (k<i && ossz-x[k] >= p)
            {
                ossz -= x[k];
                ++k;
            }
        }
        mini = min(mini, (i - k + 1));
        ++i;
    }
    cout << mini;
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/03ms1956 KiB
2Accepted0/032ms3488 KiB
3Accepted2/23ms2264 KiB
4Accepted2/23ms2432 KiB
5Wrong answer0/23ms2820 KiB
6Accepted2/26ms2984 KiB
7Accepted2/26ms2972 KiB
8Accepted2/26ms3120 KiB
9Accepted2/26ms3164 KiB
10Accepted2/26ms3072 KiB
11Accepted2/232ms4388 KiB
12Accepted2/232ms4356 KiB
13Accepted2/232ms4360 KiB
14Accepted2/232ms4356 KiB
15Accepted2/232ms4356 KiB
16Accepted2/232ms4552 KiB
17Accepted2/232ms4636 KiB
18Accepted2/232ms4720 KiB
19Accepted2/232ms4632 KiB
20Accepted2/232ms4780 KiB
21Accepted2/232ms4764 KiB
22Accepted2/232ms4632 KiB
23Wrong answer0/232ms4632 KiB
24Accepted2/232ms4780 KiB
25Accepted2/232ms4740 KiB
26Accepted2/232ms4760 KiB
27Accepted2/232ms4636 KiB