153152025-02-18 10:49:07Leventusz09Maximális szorzat (50 pont)cpp17Wrong answer 18/5061ms1560 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define MOD % 1'000'000'007
using namespace std;

signed main() {
	int N, M, b;
	cin >> N >> M >> b;
	vector<int> p, n;
	int zc = 0;
	for (int i = 0, a; i < N; i++) {
		cin >> a;
		if (a < 0) n.push_back(-a);
		else if (a > 0) p.push_back(a);
		else zc++;
	}
	sort(n.begin(), n.end(), greater<int>());
	
	while (b != n.size()) {
		M -= n[n.size()-1];
		n.pop_back();
		zc++;
	}
	int s, i;
	if (M < 0) {
		cout << -1 << endl;
		return 0;
	}
	if (M == 0) goto end;
	if (zc > M) goto end;
	M -= zc;
	while (zc--) p.push_back(1);
	
	sort(p.begin(), p.end());
	while (M) {
		int i = 1;
		p[0]++;
		M--;
		while (M && i<p.size() && p[i] <= p[i - 1]) {
			p[i]++;
			M--;
			i++;
		}
	}

	end:
	if (zc > 0) {
		cout << 0 << endl;
		return 0;
	}
	int o = 1;
	for (int& i : p) o = (unsigned long long)o * i MOD;
	for (int& i : n) o = (unsigned long long)o * i MOD;
	cout << o << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/04ms456 KiB
6Accepted2/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/26ms620 KiB
11Wrong answer0/252ms1472 KiB
12Wrong answer0/157ms1376 KiB
13Wrong answer0/11ms316 KiB
14Wrong answer0/14ms564 KiB
15Accepted1/118ms884 KiB
16Wrong answer0/123ms1076 KiB
17Accepted1/120ms944 KiB
18Accepted1/18ms400 KiB
19Runtime error0/141ms1452 KiB
20Runtime error0/132ms1560 KiB
21Runtime error0/159ms1452 KiB
22Runtime error0/126ms1536 KiB
23Wrong answer0/159ms1096 KiB
24Wrong answer0/157ms1448 KiB
25Wrong answer0/21ms316 KiB
26Wrong answer0/24ms564 KiB
27Runtime error0/229ms1016 KiB
28Runtime error0/129ms996 KiB
29Runtime error0/223ms940 KiB
30Accepted1/161ms1448 KiB
31Accepted1/134ms1448 KiB
32Accepted2/22ms508 KiB
33Accepted2/261ms1448 KiB
34Wrong answer0/161ms1516 KiB
35Wrong answer0/261ms1344 KiB
36Accepted2/261ms1448 KiB
37Accepted2/261ms1452 KiB
38Accepted2/261ms1540 KiB
39Accepted1/11ms316 KiB