152992025-02-18 09:20:43gyarturMaximális szorzat (50 pont)cpp17Wrong answer 1/50504ms792 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--;
        for(int *p = a; p < x+n-2; p++){
            if(*p > *(p+1))swap(*p,*(p+1));
            else break;
        }
        return;
    }
    int *a2 = upper_bound(x, x+n, -1);
    ++*a2;
    for(int *p = a2; p < x+n-2; p++){
        if(*p > *(p+1))swap(*p,*(p+1));
        else break;
    }
}

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/01ms508 KiB
3Wrong answer0/01ms316 KiB
4Accepted0/01ms508 KiB
5Wrong answer0/014ms508 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/22ms408 KiB
10Wrong answer0/27ms388 KiB
11Wrong answer0/268ms620 KiB
12Wrong answer0/167ms572 KiB
13Wrong answer0/14ms316 KiB
14Wrong answer0/137ms408 KiB
15Wrong answer0/193ms596 KiB
16Time limit exceeded0/1504ms508 KiB
17Wrong answer0/1119ms564 KiB
18Accepted1/110ms568 KiB
19Wrong answer0/148ms564 KiB
20Wrong answer0/137ms792 KiB
21Wrong answer0/167ms764 KiB
22Wrong answer0/130ms564 KiB
23Wrong answer0/168ms564 KiB
24Wrong answer0/167ms552 KiB
25Wrong answer0/26ms508 KiB
26Wrong answer0/27ms508 KiB
27Wrong answer0/235ms564 KiB
28Wrong answer0/135ms420 KiB
29Wrong answer0/2273ms600 KiB
30Wrong answer0/167ms728 KiB
31Wrong answer0/143ms564 KiB
32Wrong answer0/24ms316 KiB
33Wrong answer0/267ms564 KiB
34Wrong answer0/171ms568 KiB
35Wrong answer0/268ms564 KiB
36Wrong answer0/267ms564 KiB
37Wrong answer0/267ms768 KiB
38Wrong answer0/267ms564 KiB
39Wrong answer0/14ms316 KiB