153642025-02-19 09:05:47ZsBalazsMaximális szorzat (50 pont)cpp17Wrong answer 43/5075ms1988 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] * -1)) % 1000000007;
    }
    
    cout << szorzat << endl;
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms452 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/27ms456 KiB
11Accepted2/271ms1716 KiB
12Accepted1/175ms1836 KiB
13Accepted1/11ms316 KiB
14Accepted1/17ms556 KiB
15Accepted1/119ms688 KiB
16Accepted1/137ms1036 KiB
17Accepted1/121ms908 KiB
18Accepted1/113ms1120 KiB
19Wrong answer0/143ms1448 KiB
20Wrong answer0/132ms1500 KiB
21Wrong answer0/163ms1512 KiB
22Wrong answer0/127ms1548 KiB
23Accepted1/175ms1708 KiB
24Accepted1/175ms1988 KiB
25Accepted2/21ms316 KiB
26Accepted2/26ms416 KiB
27Wrong answer0/232ms952 KiB
28Wrong answer0/130ms892 KiB
29Accepted2/223ms940 KiB
30Accepted1/164ms1452 KiB
31Accepted1/134ms1556 KiB
32Accepted2/22ms412 KiB
33Accepted2/264ms1512 KiB
34Accepted1/165ms1468 KiB
35Accepted2/267ms1448 KiB
36Accepted2/263ms1340 KiB
37Accepted2/264ms1540 KiB
38Accepted2/264ms1452 KiB
39Accepted1/12ms316 KiB