153692025-02-19 09:15:19ZsBalazsMaximális szorzat (50 pont)cpp17Wrong answer 44/5082ms1932 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);
    }
    
    if (hasznalhato > 0) {
        priority_queue<int> minus;
        
        for (int i = valt; negati.size() > i; i++) {
            minus.push(negati[i]);
        }
        
        while (hasznalhato--) {
            int current = minus.top();
            minus.pop();
            
            minus.push((current+1));
        }
        
        int countNega = 0;
        
        long long szorzat = 1;
    
        while (!szamok.empty()) {
            szorzat = (szorzat * (long long)(szamok.top() * -1)) % 1000000007;
            szamok.pop();
        }
        
        while (!minus.empty()) {
            if (minus.top() < 0) {
                countNega++;
            }
            
            szorzat = (szorzat * (long long)(minus.top())) % 1000000007;
            minus.pop();
        }
        
        if (countNega != b) {
            cout << -1 << endl;
        } else {
            cout << szorzat << endl;
        }
        
        return 0;
    }
    
    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
base44/50
1Accepted0/01ms316 KiB
2Accepted0/01ms508 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms612 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/27ms456 KiB
11Accepted2/271ms1872 KiB
12Accepted1/176ms1916 KiB
13Accepted1/11ms316 KiB
14Accepted1/17ms584 KiB
15Accepted1/118ms880 KiB
16Accepted1/139ms944 KiB
17Accepted1/121ms932 KiB
18Accepted1/110ms1096 KiB
19Wrong answer0/165ms1876 KiB
20Wrong answer0/156ms1832 KiB
21Wrong answer0/182ms1932 KiB
22Accepted1/143ms1924 KiB
23Accepted1/178ms1708 KiB
24Accepted1/178ms1804 KiB
25Accepted2/22ms396 KiB
26Accepted2/26ms316 KiB
27Wrong answer0/246ms1028 KiB
28Wrong answer0/146ms1072 KiB
29Accepted2/223ms944 KiB
30Accepted1/161ms1540 KiB
31Accepted1/132ms1456 KiB
32Accepted2/22ms316 KiB
33Accepted2/263ms1480 KiB
34Accepted1/164ms1452 KiB
35Accepted2/265ms1516 KiB
36Accepted2/261ms1532 KiB
37Accepted2/261ms1520 KiB
38Accepted2/261ms1480 KiB
39Accepted1/12ms316 KiB