39462023-03-06 12:03:36tamasmarkLeggyorsabb pénzkeresés (50)cpp17Time limit exceeded 36/50300ms5880 KiB
// penz kereses.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int n, i, mini, p, j,sum,db,a;
vector<long long>x;
bool t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> p;
    x.resize(n + 1);
    for (i = 1; i <= n; ++i)
    {
        cin >> x[i];
    }
    /*i = 1;
    
    while (i <= n)
    {
        if (sum == 0) a = i;
        sum += x[i];
        db++;
        if (sum >= p)
        {
            if (db < mini) mini = db;
            db = 0;
            sum = 0;
            i = a + 1;
        }
        else i++;
    }*/
    mini = INT_MAX;
    for (i = 1; i <= n; ++i)
    {
        if (!t)
        {
            sum += x[i];
            db++;
            if (sum >= p)
            {
                if (db < mini)
                {
                    mini = db;
                    t = true;
                    i = i - (db - 1);
                }
            }
        }
        else
        {
            sum = 0;
            for (j = 0; j <= mini-1; ++j)
            {
                if(i+j<=n) sum += x[i + j];
                if (sum >= p)
                {
                    if (j + 1 < mini) mini = j + 1;
                }
            }
        }

    }
    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
base36/50
1Accepted0/03ms1760 KiB
2Time limit exceeded0/0300ms2020 KiB
3Accepted2/23ms2248 KiB
4Accepted2/23ms2480 KiB
5Accepted2/23ms2580 KiB
6Accepted2/28ms3004 KiB
7Accepted2/228ms2916 KiB
8Accepted2/239ms2944 KiB
9Accepted2/28ms3196 KiB
10Accepted2/234ms3156 KiB
11Accepted2/213ms4668 KiB
12Time limit exceeded0/2237ms3292 KiB
13Time limit exceeded0/2256ms5064 KiB
14Accepted2/274ms5016 KiB
15Time limit exceeded0/2247ms5156 KiB
16Accepted2/271ms5148 KiB
17Accepted2/261ms5192 KiB
18Accepted2/2104ms5116 KiB
19Time limit exceeded0/2252ms3800 KiB
20Time limit exceeded0/2202ms5312 KiB
21Accepted2/2115ms5224 KiB
22Accepted2/2170ms5228 KiB
23Time limit exceeded0/2248ms3848 KiB
24Accepted2/2164ms5296 KiB
25Time limit exceeded0/2215ms5356 KiB
26Accepted2/2111ms5612 KiB
27Accepted2/2108ms5880 KiB