147252025-01-30 07:59:47KateTaylorMaximális szorzat (50 pont)cpp17Wrong answer 22/5061ms1556 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
	ll n, k, b, z = 0, needed = 0;
	cin >> n >> k >> b;
	vector<ll> pos;
	vector<ll> neg;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		if (!x) z++;
		else if (x > 0) pos.push_back(x);
		else {
			neg.push_back(x);
			needed -= x;
		}
	}
	if (b > neg.size()) {
		cout << -1;
		return 0;
	}
	sort(neg.begin(), neg.end());
	sort(pos.begin(), pos.end());
	for (int i = 0; i < b; i++) needed += neg[i];
	if (needed > k) {
		cout << -1;
		return 0;
	}
	k -= needed;
	z += neg.size() - b;
	if (k < z) {
		cout << 0;
		return 0;
	}
	k -= z;
	while (z--) pos.insert(pos.begin(), 1);
	int ptr = 0;
	while (k--) {
		pos[ptr]++;
		if (ptr == pos.size() - 1 || pos[ptr] <= pos[ptr + 1]) ptr = 0;
		else ptr++;
	}
	ll ans = 1;
	for (int x : pos) {
		ans *= x;
		ans %= 1000000007;
	}
	for (int i = 1; i <= b; i++) {
		ans *= neg[neg.size() - i];
		ans %= 1000000007;
	}
	cout << ans;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base22/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/04ms564 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/26ms608 KiB
11Accepted2/254ms1452 KiB
12Accepted1/157ms1464 KiB
13Wrong answer0/11ms316 KiB
14Wrong answer0/14ms752 KiB
15Accepted1/120ms932 KiB
16Wrong answer0/123ms1068 KiB
17Accepted1/120ms816 KiB
18Accepted1/18ms400 KiB
19Runtime error0/141ms1352 KiB
20Runtime error0/130ms1344 KiB
21Runtime error0/159ms1504 KiB
22Runtime error0/124ms1452 KiB
23Accepted1/159ms1264 KiB
24Accepted1/157ms1452 KiB
25Wrong answer0/21ms332 KiB
26Wrong answer0/26ms576 KiB
27Runtime error0/229ms960 KiB
28Runtime error0/129ms988 KiB
29Accepted2/218ms1012 KiB
30Wrong answer0/159ms1472 KiB
31Accepted1/143ms1456 KiB
32Wrong answer0/22ms316 KiB
33Wrong answer0/259ms1316 KiB
34Accepted1/159ms1516 KiB
35Wrong answer0/261ms1448 KiB
36Wrong answer0/259ms1556 KiB
37Wrong answer0/261ms1452 KiB
38Wrong answer0/259ms1548 KiB
39Wrong answer0/11ms316 KiB