139312025-01-09 11:29:56NeMMaximális szorzat (50 pont)cpp17Wrong answer 19/5059ms1164 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) {
		if ((a[ln]*-1) >= k) {
			k += a[ln];
			a[ln] = 0;
			ln--;
		} else {
			a[0] += k;
			k = 0;
		}
	}

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

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


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