67262023-12-18 10:32:04zsebiLeggyorsabb pénzkeresés (50)cpp17Accepted 50/50195ms5176 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long 
using namespace std;

ll n, p, maxi = 0;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	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;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/0187ms3520 KiB
3Accepted2/23ms2228 KiB
4Accepted2/23ms2580 KiB
5Accepted2/23ms2536 KiB
6Accepted2/26ms2872 KiB
7Accepted2/214ms2956 KiB
8Accepted2/219ms2932 KiB
9Accepted2/26ms3204 KiB
10Accepted2/217ms3072 KiB
11Accepted2/213ms4332 KiB
12Accepted2/2195ms4332 KiB
13Accepted2/2135ms4676 KiB
14Accepted2/245ms4552 KiB
15Accepted2/2130ms4544 KiB
16Accepted2/243ms4764 KiB
17Accepted2/237ms4684 KiB
18Accepted2/259ms4684 KiB
19Accepted2/2165ms4752 KiB
20Accepted2/2108ms5020 KiB
21Accepted2/265ms4928 KiB
22Accepted2/292ms4972 KiB
23Accepted2/2188ms4944 KiB
24Accepted2/289ms5092 KiB
25Accepted2/2114ms5176 KiB
26Accepted2/263ms4824 KiB
27Accepted2/261ms4824 KiB