147242025-01-30 07:53:42KateTaylorMaximális szorzat (50 pont)cpp17Wrong answer 6/5059ms1568 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;
	for (int i = 1; i <= b; i++) {
		ans *= neg[neg.size() - i];
	}
	cout << ans;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/04ms556 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/24ms424 KiB
11Wrong answer0/252ms1444 KiB
12Wrong answer0/156ms1448 KiB
13Wrong answer0/11ms316 KiB
14Wrong answer0/14ms568 KiB
15Accepted1/120ms932 KiB
16Wrong answer0/123ms1032 KiB
17Accepted1/120ms944 KiB
18Accepted1/18ms400 KiB
19Runtime error0/141ms1476 KiB
20Runtime error0/129ms1500 KiB
21Runtime error0/159ms1544 KiB
22Runtime error0/124ms1516 KiB
23Wrong answer0/159ms1180 KiB
24Wrong answer0/156ms1452 KiB
25Wrong answer0/21ms316 KiB
26Wrong answer0/24ms460 KiB
27Runtime error0/229ms1044 KiB
28Runtime error0/129ms940 KiB
29Accepted2/218ms956 KiB
30Wrong answer0/159ms1528 KiB
31Accepted1/143ms1508 KiB
32Wrong answer0/22ms316 KiB
33Wrong answer0/259ms1468 KiB
34Wrong answer0/159ms1348 KiB
35Wrong answer0/259ms1344 KiB
36Wrong answer0/259ms1568 KiB
37Wrong answer0/259ms1516 KiB
38Wrong answer0/259ms1520 KiB
39Wrong answer0/11ms316 KiB