141722025-01-10 08:11:00NeMMaximális szorzat (50 pont)cpp17Wrong answer 42/5059ms1080 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))) {
			int 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
base42/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms320 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms436 KiB
11Accepted2/252ms1060 KiB
12Accepted1/156ms1060 KiB
13Accepted1/11ms404 KiB
14Accepted1/14ms316 KiB
15Accepted1/120ms568 KiB
16Accepted1/121ms604 KiB
17Accepted1/121ms608 KiB
18Wrong answer0/19ms564 KiB
19Wrong answer0/141ms1060 KiB
20Wrong answer0/130ms1076 KiB
21Wrong answer0/159ms1052 KiB
22Wrong answer0/125ms1060 KiB
23Accepted1/157ms1064 KiB
24Accepted1/156ms1060 KiB
25Accepted2/21ms316 KiB
26Accepted2/24ms316 KiB
27Wrong answer0/229ms608 KiB
28Wrong answer0/129ms564 KiB
29Accepted2/223ms564 KiB
30Accepted1/159ms1060 KiB
31Accepted1/143ms1076 KiB
32Accepted2/21ms316 KiB
33Accepted2/259ms1056 KiB
34Accepted1/159ms1064 KiB
35Accepted2/259ms1080 KiB
36Accepted2/259ms1056 KiB
37Accepted2/259ms1056 KiB
38Accepted2/259ms1076 KiB
39Accepted1/11ms316 KiB