152982025-02-18 09:14:11gyarturMaximális szorzat (50 pont)cpp17Wrong answer 1/50587ms796 KiB
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int x[100000];
int n, k, b;
int drbNegativ;

void Beolvas(){
    cin>>n>>k>>b;
    for(int i = 0; i < n; i++)cin>>x[i];
}

int Negativdrb(){
    int drb = 0;
    for(int i = 0; i < n; i++){
        if(x[i] < 0)drb++;
    }
    return drb;
}

int* LegnagyobbNegativ(){
    int *a = upper_bound(x, x+n, 0)-1;
    for(int *p = a; p >= x; p--){
        if(*p < 0)return p;
    }
    return a;
}

void Lepes(){
    if(drbNegativ > b){
        int *a = LegnagyobbNegativ();
        ++*a;
        if(*a >= 0)drbNegativ--;
        while(*a > *(a+1) && a != x+n-1){
            swap(*a,*(a+1));
            a++;
        }
        return;
    }
    int *a2 = upper_bound(x, x+n, -1);
    ++*a2;
    while(*a2 > *(a2+1) && a2 != x+n-1){
        swap(*a2,*(a2+1));
        a2++;
    }
}

int main(){
    Beolvas();
    sort(x, x+n);
    drbNegativ = Negativdrb();
    while(k > 0){
        Lepes();
        k--;
    }
    int p = 1;
    for(int i = 0; i < n; i++){
        p *= x[i];
    }
    cout<<p;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms504 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/07ms316 KiB
6Wrong answer0/21ms328 KiB
7Wrong answer0/21ms500 KiB
8Wrong answer0/21ms508 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/26ms316 KiB
11Wrong answer0/259ms760 KiB
12Wrong answer0/161ms760 KiB
13Wrong answer0/13ms408 KiB
14Wrong answer0/112ms452 KiB
15Wrong answer0/193ms512 KiB
16Wrong answer0/1107ms564 KiB
17Wrong answer0/1119ms600 KiB
18Accepted1/19ms756 KiB
19Wrong answer0/175ms764 KiB
20Wrong answer0/164ms556 KiB
21Wrong answer0/193ms796 KiB
22Wrong answer0/159ms612 KiB
23Wrong answer0/164ms740 KiB
24Wrong answer0/161ms756 KiB
25Wrong answer0/22ms316 KiB
26Wrong answer0/24ms316 KiB
27Time limit exceeded0/2587ms652 KiB
28Time limit exceeded0/1587ms740 KiB
29Wrong answer0/271ms564 KiB
30Wrong answer0/163ms568 KiB
31Wrong answer0/141ms564 KiB
32Wrong answer0/24ms316 KiB
33Wrong answer0/263ms756 KiB
34Wrong answer0/164ms580 KiB
35Wrong answer0/264ms576 KiB
36Wrong answer0/264ms564 KiB
37Wrong answer0/264ms724 KiB
38Wrong answer0/263ms732 KiB
39Wrong answer0/14ms316 KiB