142232025-01-10 09:56:55NeMMaximális szorzat (50 pont)cpp17Wrong answer 40/5059ms1076 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k, b, ln = 0;
	cin >> n >> k >> b;
	vector <int> a (n, INT_MIN);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	a.push_back(INT_MAX);
	for (int i = 0; i < n+1; i++) {
		if (a[i] >= 0) {
			ln = i-1;
			break;
		}
	}
	

	if (ln < b-1) {
		cout << -1;
		return 0;
	}

	while (ln > b-1) {
		/*if (k == 0) {
			cout << -1;
			return 0;
		}*/

		if (a[ln] < 0) {
			a[ln]++;
			k--;
		} else {
			ln--;
		}
	}

	if (ln%2 == 0) {
		int i = 0;
		while ((k > 0) && (i <= ln)) {
			if (a[i] >= k) {
				k -= (a[i]-1);
				a[i] = -1;
				i++;
			} else {
				a[i] -= k;
				k = 0;
			}
		}

		if (k > 0) {
			cout << -1;
			return 0;
		}
	}

	long long s = k;
	for (int i = ln+2; i < n+1; i++) {
		s += a[i-1];

		if (a[i] >= s/(i-(ln+1))) {
			long long d = s/(i-(ln+1)), r = s%(i-(ln+1));
			for (int j = ln+1; j < i; j++) {
				k -= (d-a[j]);
				a[j] += (d-a[j]);

				if (r > 0) {
					a[j]++;
					r--;
				}
			}

			break;
		}
	}


	long long c = 1;
	for (int i = 0; i < n; i++) {
		c *= a[i];
		c = c % 1000000007;
	}
	cout << c;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/50
1Accepted0/01ms508 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms508 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms316 KiB
11Accepted2/252ms1060 KiB
12Accepted1/156ms1056 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms436 KiB
15Wrong answer0/123ms608 KiB
16Accepted1/121ms608 KiB
17Wrong answer0/121ms564 KiB
18Accepted1/110ms564 KiB
19Wrong answer0/141ms1060 KiB
20Wrong answer0/130ms1060 KiB
21Wrong answer0/159ms1064 KiB
22Wrong answer0/125ms1072 KiB
23Accepted1/159ms1076 KiB
24Accepted1/156ms1076 KiB
25Accepted2/21ms316 KiB
26Accepted2/24ms316 KiB
27Wrong answer0/229ms564 KiB
28Wrong answer0/129ms604 KiB
29Accepted2/223ms612 KiB
30Accepted1/159ms1052 KiB
31Wrong answer0/143ms1076 KiB
32Accepted2/21ms404 KiB
33Accepted2/259ms1076 KiB
34Accepted1/159ms1064 KiB
35Accepted2/259ms1056 KiB
36Accepted2/259ms1076 KiB
37Accepted2/259ms1076 KiB
38Accepted2/259ms1052 KiB
39Accepted1/11ms316 KiB