6647 2023. 12. 15 09:25:58 zsebi Leggyorsabb pénzkeresés (50) cpp17 Hibás válasz 46/50 32ms 4780 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
Részfeladat Összpont Teszt Verdikt Idő Memória
base 46/50
1 Elfogadva 0/0 3ms 1956 KiB
2 Elfogadva 0/0 32ms 3488 KiB
3 Elfogadva 2/2 3ms 2264 KiB
4 Elfogadva 2/2 3ms 2432 KiB
5 Hibás válasz 0/2 3ms 2820 KiB
6 Elfogadva 2/2 6ms 2984 KiB
7 Elfogadva 2/2 6ms 2972 KiB
8 Elfogadva 2/2 6ms 3120 KiB
9 Elfogadva 2/2 6ms 3164 KiB
10 Elfogadva 2/2 6ms 3072 KiB
11 Elfogadva 2/2 32ms 4388 KiB
12 Elfogadva 2/2 32ms 4356 KiB
13 Elfogadva 2/2 32ms 4360 KiB
14 Elfogadva 2/2 32ms 4356 KiB
15 Elfogadva 2/2 32ms 4356 KiB
16 Elfogadva 2/2 32ms 4552 KiB
17 Elfogadva 2/2 32ms 4636 KiB
18 Elfogadva 2/2 32ms 4720 KiB
19 Elfogadva 2/2 32ms 4632 KiB
20 Elfogadva 2/2 32ms 4780 KiB
21 Elfogadva 2/2 32ms 4764 KiB
22 Elfogadva 2/2 32ms 4632 KiB
23 Hibás válasz 0/2 32ms 4632 KiB
24 Elfogadva 2/2 32ms 4780 KiB
25 Elfogadva 2/2 32ms 4740 KiB
26 Elfogadva 2/2 32ms 4760 KiB
27 Elfogadva 2/2 32ms 4636 KiB