66312023-12-14 07:47:20zsebiLeggyorsabb pénzkeresés (50)cpp17Time limit exceeded 46/50214ms6232 KiB
// leggyors_penzkereses.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, p, maxi = 0;
int main()
{
	cin >> n >> p;
	vector<ll>x(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		ll a;
		cin >> a;
		x[i] = x[i - 1] + a;
		if (a >= p)
		{
			cout << "1";
			return 0;
		}
	}
	if (x[n] < p)
	{
		cout << "0";
		return 0;
	}
	ll mintav = n;
	for (int i = 1; i <= n; ++i)
	{
		ll sum;
		for (int j = i - 1; j > i - mintav + 1; --j)
		{
			if (j > 0)
			{
				sum=x[i]-x[j-1];
				if (sum >= p)
				{
					mintav = i - j + 1;
					break;
				}

			}
			else 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
base46/50
1Accepted0/03ms1816 KiB
2Time limit exceeded0/0203ms3532 KiB
3Accepted2/23ms2344 KiB
4Accepted2/23ms2600 KiB
5Accepted2/23ms2508 KiB
6Accepted2/28ms2964 KiB
7Accepted2/217ms3176 KiB
8Accepted2/221ms3296 KiB
9Accepted2/28ms3088 KiB
10Accepted2/218ms3084 KiB
11Accepted2/230ms4496 KiB
12Time limit exceeded0/2214ms4708 KiB
13Accepted2/2151ms4920 KiB
14Accepted2/261ms5128 KiB
15Accepted2/2149ms5268 KiB
16Accepted2/259ms5356 KiB
17Accepted2/257ms5356 KiB
18Accepted2/276ms5352 KiB
19Accepted2/2182ms5564 KiB
20Accepted2/2126ms5660 KiB
21Accepted2/282ms5624 KiB
22Accepted2/2108ms5660 KiB
23Time limit exceeded0/2206ms5664 KiB
24Accepted2/2105ms5892 KiB
25Accepted2/2131ms6092 KiB
26Accepted2/279ms6232 KiB
27Accepted2/279ms6104 KiB