153482025-02-19 08:41:10NeMMaximális szorzat (50 pont)cpp17Wrong answer 38/5059ms1972 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k, b, ln = 0;
	cin >> n >> k >> b;
	vector <long long> 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 (k > 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
base38/50
1Accepted0/01ms316 KiB
2Accepted0/01ms508 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms564 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/26ms564 KiB
11Accepted2/252ms1956 KiB
12Accepted1/156ms1968 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms476 KiB
15Wrong answer0/121ms1068 KiB
16Accepted1/121ms1056 KiB
17Wrong answer0/121ms1060 KiB
18Accepted1/110ms1064 KiB
19Wrong answer0/141ms1972 KiB
20Wrong answer0/129ms1960 KiB
21Wrong answer0/159ms1964 KiB
22Wrong answer0/125ms1844 KiB
23Accepted1/159ms1836 KiB
24Accepted1/156ms1956 KiB
25Accepted2/21ms316 KiB
26Accepted2/24ms564 KiB
27Wrong answer0/229ms1060 KiB
28Wrong answer0/129ms1060 KiB
29Wrong answer0/223ms1056 KiB
30Accepted1/159ms1960 KiB
31Wrong answer0/143ms1960 KiB
32Accepted2/21ms316 KiB
33Accepted2/259ms1960 KiB
34Accepted1/159ms1960 KiB
35Accepted2/259ms1844 KiB
36Accepted2/259ms1964 KiB
37Accepted2/259ms1844 KiB
38Accepted2/259ms1844 KiB
39Accepted1/11ms316 KiB