66312023-12-14 07:47:20zsebiLeggyorsabb pénzkeresés (50)cpp17Időlimit túllépés 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base46/50
1Elfogadva0/03ms1816 KiB
2Időlimit túllépés0/0203ms3532 KiB
3Elfogadva2/23ms2344 KiB
4Elfogadva2/23ms2600 KiB
5Elfogadva2/23ms2508 KiB
6Elfogadva2/28ms2964 KiB
7Elfogadva2/217ms3176 KiB
8Elfogadva2/221ms3296 KiB
9Elfogadva2/28ms3088 KiB
10Elfogadva2/218ms3084 KiB
11Elfogadva2/230ms4496 KiB
12Időlimit túllépés0/2214ms4708 KiB
13Elfogadva2/2151ms4920 KiB
14Elfogadva2/261ms5128 KiB
15Elfogadva2/2149ms5268 KiB
16Elfogadva2/259ms5356 KiB
17Elfogadva2/257ms5356 KiB
18Elfogadva2/276ms5352 KiB
19Elfogadva2/2182ms5564 KiB
20Elfogadva2/2126ms5660 KiB
21Elfogadva2/282ms5624 KiB
22Elfogadva2/2108ms5660 KiB
23Időlimit túllépés0/2206ms5664 KiB
24Elfogadva2/2105ms5892 KiB
25Elfogadva2/2131ms6092 KiB
26Elfogadva2/279ms6232 KiB
27Elfogadva2/279ms6104 KiB