153662025-02-19 09:08:16ZsBalazsMaximális szorzat (50 pont)cpp17Wrong answer 43/5075ms1964 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k, b;
	cin >> n >> k >> b;
	
	vector<int> elemek;
	
	for (int i = 0; n > i; i++) {
	    int temp;
	    cin >> temp;
	    
	    elemek.push_back(temp);
	}
	
	vector<int> negati;
	vector<int> pozi;
	
	for (int elem : elemek) {
	    if (elem < 0) {
	        negati.push_back(elem);
	    } else {
	        pozi.push_back(elem);
	    }
	}
	
	// csokkeno sorrend
	sort(negati.rbegin(), negati.rend());
    
    int valt = negati.size() - b;
    
    if (valt < 0) {
        cout << -1 << endl; 
        return 0;
    }
    
    int felhasznalt = 0;
    
    for (int i = 0; valt > i; i++) {
        felhasznalt += (0 - negati[i]);
        pozi.push_back(0);
    }
    
    int hasznalhato = k - felhasznalt;
    
    if (hasznalhato < 0) {
        cout << -1 << endl; 
        return 0;
    }
    
    priority_queue<int> szamok;
    
    for (int szam : pozi) {
        szamok.push(szam * -1);
    }
    
    while (hasznalhato-- && !szamok.empty()) {
        int current = szamok.top() * -1;
        szamok.pop();
        
        szamok.push((current+1) * -1);
    }
    
    long long szorzat = 1;
    
    while (!szamok.empty()) {
        szorzat = (szorzat * (long long)(szamok.top() * -1)) % 1000000007;
        szamok.pop();
    }
    
    for (int i = valt; negati.size() > i; i++) {
        szorzat = (szorzat * (long long)(negati[i])) % 1000000007;
    }
    
    cout << szorzat << endl;
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms316 KiB
2Accepted0/01ms508 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms612 KiB
6Accepted2/21ms352 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms404 KiB
9Accepted2/21ms316 KiB
10Accepted2/27ms596 KiB
11Accepted2/270ms1836 KiB
12Accepted1/175ms1964 KiB
13Accepted1/11ms412 KiB
14Accepted1/17ms504 KiB
15Accepted1/118ms688 KiB
16Accepted1/137ms888 KiB
17Accepted1/121ms884 KiB
18Accepted1/113ms1096 KiB
19Wrong answer0/145ms1464 KiB
20Wrong answer0/132ms1532 KiB
21Wrong answer0/163ms1452 KiB
22Wrong answer0/126ms1488 KiB
23Accepted1/175ms1704 KiB
24Accepted1/175ms1896 KiB
25Accepted2/21ms316 KiB
26Accepted2/26ms316 KiB
27Wrong answer0/230ms812 KiB
28Wrong answer0/132ms928 KiB
29Accepted2/223ms940 KiB
30Accepted1/164ms1544 KiB
31Accepted1/134ms1504 KiB
32Accepted2/22ms316 KiB
33Accepted2/264ms1404 KiB
34Accepted1/165ms1536 KiB
35Accepted2/267ms1316 KiB
36Accepted2/264ms1452 KiB
37Accepted2/264ms1452 KiB
38Accepted2/264ms1420 KiB
39Accepted1/12ms508 KiB