147262025-01-30 08:15:47KateTaylorMaximális szorzat (50 pont)cpp17Wrong answer 29/5063ms1472 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 (neg.size() == n && k >= needed - n) {
		cout << -1;
		return 0;
	}
	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;
	if (pos.empty()) {
		while (k--) {
			neg[ptr]++;
			if (ptr == n - 1 || neg[ptr] <= neg[ptr + 1]) ptr = 0;
			else ptr++;
		}
		ll ans = 1;
		for (ll x : neg) {
			ans *= x;
			ans %= 1000000007;
		}
		cout << ans;
		return 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
base29/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms508 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/04ms504 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms344 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms564 KiB
11Accepted2/252ms1444 KiB
12Accepted1/157ms1400 KiB
13Wrong answer0/12ms508 KiB
14Wrong answer0/14ms572 KiB
15Accepted1/120ms828 KiB
16Wrong answer0/123ms944 KiB
17Accepted1/120ms944 KiB
18Accepted1/18ms400 KiB
19Accepted1/143ms1452 KiB
20Accepted1/132ms1452 KiB
21Accepted1/163ms1448 KiB
22Accepted1/123ms1452 KiB
23Accepted1/159ms1272 KiB
24Accepted1/161ms1452 KiB
25Wrong answer0/21ms316 KiB
26Wrong answer0/24ms400 KiB
27Accepted2/232ms1036 KiB
28Accepted1/132ms944 KiB
29Accepted2/218ms944 KiB
30Wrong answer0/161ms1452 KiB
31Accepted1/143ms1472 KiB
32Wrong answer0/21ms316 KiB
33Wrong answer0/261ms1376 KiB
34Accepted1/159ms1452 KiB
35Wrong answer0/259ms1452 KiB
36Wrong answer0/261ms1452 KiB
37Wrong answer0/261ms1452 KiB
38Wrong answer0/259ms1344 KiB
39Wrong answer0/11ms328 KiB