66502023-12-15 11:42:56tamasmarkLeggyorsabb pénzkeresés (50)cpp17Wrong answer 6/5035ms5376 KiB
// leggyorsabb penzkereses.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>

using namespace std;

int ball, jobb, mini, k, n, i, j,sum;

int main()
{
    cin >> n >> k;
    deque<int>x(n + 1);
    for (i = 1; i <= n; ++i) cin >> x[i];
    ball = 1;
    jobb = 1;
    while (sum < k)
    {
        sum += x[jobb];
        if (sum >= k) break;
        else jobb++;
    }
    mini = jobb - ball + 1;
    while (jobb<=n)
    {
        sum -= x[ball];
        ball++;
        if (sum >= k&&jobb-ball+1<mini)
        {
            mini = jobb-ball + 1;
            if (jobb < n)
            {
                jobb++;
                sum += x[jobb];
            }
            else break;
        }
        else
        {
            jobb++;
            sum += x[jobb];
        }
    }
    cout << mini;
    return 0;
}

/*


8 11
3 6 4 2 3 7 2 9
*/
// 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
base6/50
1Wrong answer0/03ms2088 KiB
2Wrong answer0/030ms3104 KiB
3Wrong answer0/23ms2320 KiB
4Wrong answer0/23ms2352 KiB
5Accepted2/23ms2568 KiB
6Wrong answer0/26ms2848 KiB
7Wrong answer0/26ms2804 KiB
8Wrong answer0/26ms3096 KiB
9Wrong answer0/26ms3200 KiB
10Wrong answer0/26ms3480 KiB
11Accepted2/232ms4096 KiB
12Wrong answer0/234ms4444 KiB
13Wrong answer0/230ms4400 KiB
14Wrong answer0/230ms4420 KiB
15Wrong answer0/232ms4508 KiB
16Wrong answer0/230ms4732 KiB
17Wrong answer0/230ms4812 KiB
18Wrong answer0/234ms4960 KiB
19Wrong answer0/235ms4944 KiB
20Wrong answer0/230ms5292 KiB
21Wrong answer0/230ms5128 KiB
22Wrong answer0/230ms5140 KiB
23Accepted2/230ms5028 KiB
24Wrong answer0/230ms5364 KiB
25Wrong answer0/230ms5300 KiB
26Wrong answer0/230ms5376 KiB
27Wrong answer0/230ms5376 KiB