153012025-02-18 09:28:07gyarturMaximális szorzat (50 pont)cpp17Wrong answer 1/50503ms796 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 x;
}

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 return;
        }
        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 return;
    }
}

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
3Wrong answer0/01ms316 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/014ms444 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/22ms316 KiB
10Wrong answer0/27ms448 KiB
11Wrong answer0/267ms700 KiB
12Wrong answer0/165ms796 KiB
13Wrong answer0/14ms416 KiB
14Wrong answer0/137ms448 KiB
15Wrong answer0/193ms564 KiB
16Time limit exceeded0/1503ms564 KiB
17Wrong answer0/1120ms600 KiB
18Accepted1/110ms612 KiB
19Wrong answer0/148ms564 KiB
20Wrong answer0/137ms564 KiB
21Wrong answer0/165ms568 KiB
22Wrong answer0/129ms564 KiB
23Wrong answer0/168ms568 KiB
24Wrong answer0/165ms784 KiB
25Wrong answer0/26ms508 KiB
26Wrong answer0/27ms544 KiB
27Wrong answer0/239ms528 KiB
28Wrong answer0/135ms432 KiB
29Wrong answer0/2273ms472 KiB
30Wrong answer0/165ms560 KiB
31Wrong answer0/143ms756 KiB
32Wrong answer0/24ms316 KiB
33Wrong answer0/265ms756 KiB
34Wrong answer0/170ms560 KiB
35Wrong answer0/268ms632 KiB
36Wrong answer0/265ms564 KiB
37Wrong answer0/265ms564 KiB
38Wrong answer0/267ms564 KiB
39Wrong answer0/14ms316 KiB