66302023-12-14 07:44:31zsebiLeggyorsabb pénzkeresés (50)cpp17Time limit exceeded 40/50300ms14792 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)
	{
		cin >> x[i];
		if (x[i] >= p)
		{
			cout << "1";
			return 0;
		}
	}
	
	ll mintav = n;
	for (int i = 1; i <= n; ++i)
	{
		ll sum = x[i];
		for (int j = i - 1; j > i - mintav + 1; --j)
		{
			if (j > 0)
			{
				sum += x[j];
				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
base40/50
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0300ms2440 KiB
3Accepted2/23ms2512 KiB
4Accepted2/23ms2652 KiB
5Accepted2/23ms2864 KiB
6Accepted2/29ms3308 KiB
7Accepted2/224ms3588 KiB
8Accepted2/232ms3724 KiB
9Accepted2/28ms3884 KiB
10Accepted2/228ms4216 KiB
11Accepted2/232ms5892 KiB
12Time limit exceeded0/2300ms5312 KiB
13Time limit exceeded0/2232ms7324 KiB
14Accepted2/283ms7700 KiB
15Time limit exceeded0/2226ms8180 KiB
16Accepted2/281ms8664 KiB
17Accepted2/272ms9272 KiB
18Accepted2/2108ms10124 KiB
19Time limit exceeded0/2270ms9264 KiB
20Accepted2/2189ms11172 KiB
21Accepted2/2118ms11780 KiB
22Accepted2/2162ms12408 KiB
23Time limit exceeded0/2263ms11284 KiB
24Accepted2/2158ms13340 KiB
25Accepted2/2200ms13832 KiB
26Accepted2/2114ms14316 KiB
27Accepted2/2112ms14792 KiB