27102023-01-19 09:50:45bzsofiaLeggyorsabb pénzkeresés (50)cpp11Accepted 50/50159ms6084 KiB
// leggyorsabb penz.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>

using namespace std;

long long mintav, n, p, j, i, sum;

int main()
{
    cin >> n >> p;
    mintav=n;
    vector <long long> x(n + 1);

    for (i = 1; i <= n; ++i)
    {
        cin >> x[i];
        x[i] += x[i - 1];
    }

    for (i = 1; i <= n; ++i)
    {
        for (j = i; j <= min(n,i+mintav-2); ++j)
        {
            sum = x[j] - x[i-1];
            if (sum >= p)
            {
                mintav = j - i +1;
                break;
            }
        }
    }

    cout << mintav;

    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
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/0153ms3412 KiB
3Accepted2/22ms2120 KiB
4Accepted2/22ms2308 KiB
5Accepted2/22ms2512 KiB
6Accepted2/27ms2664 KiB
7Accepted2/213ms2968 KiB
8Accepted2/216ms3168 KiB
9Accepted2/27ms3376 KiB
10Accepted2/214ms3320 KiB
11Accepted2/230ms4732 KiB
12Accepted2/2159ms4936 KiB
13Accepted2/2116ms4964 KiB
14Accepted2/252ms5180 KiB
15Accepted2/2114ms5172 KiB
16Accepted2/252ms5300 KiB
17Accepted2/248ms5384 KiB
18Accepted2/263ms5384 KiB
19Accepted2/2138ms5376 KiB
20Accepted2/297ms5504 KiB
21Accepted2/268ms5580 KiB
22Accepted2/286ms5708 KiB
23Accepted2/2156ms5908 KiB
24Accepted2/283ms6000 KiB
25Accepted2/2103ms6000 KiB
26Accepted2/265ms6084 KiB
27Accepted2/264ms6076 KiB