152342025-02-17 12:25:37tamasnagyMaximális szorzat (50 pont)cpp17Wrong answer 0/50600ms768 KiB
#include <iostream>
using namespace std;
int a[100001];

int minkeres(int n) {
    int mini = a[0];
    int minin = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] < mini) {
            mini = a[i];
            minin = i;
        }
    }
    return minin;
}
int minkeres0(int n) {
    int mini = 1000000000;
    int minin = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < mini && a[i]>=0) {
            mini = a[i];
            minin = i;
        }
    }
    return minin;
}
int main()
{
    int n, k, b;
    cin >> n >> k >> b;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int db=0;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
            db++;
        }
    }
    while (b < db) {
        int minindex=minkeres(n);
        k -= abs(a[minindex]);
        a[minindex] = 0;
        db--;
    }
    while (k) {
        int x = minkeres0(n);
        k--;
        a[x]++;
    }
    int s=1;
    for (int i = 0; i < n; i++) {
        s *= a[i];
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << ' ';
    }
    if (db > b+1) {
        cout << -1;
    }
    else cout << s;

}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/01ms500 KiB
4Wrong answer0/01ms316 KiB
5Time limit exceeded0/0598ms508 KiB
6Wrong answer0/21ms328 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/23ms316 KiB
10Wrong answer0/2196ms444 KiB
11Time limit exceeded0/2600ms580 KiB
12Time limit exceeded0/1600ms668 KiB
13Time limit exceeded0/1583ms316 KiB
14Time limit exceeded0/1582ms316 KiB
15Time limit exceeded0/1600ms564 KiB
16Time limit exceeded0/1600ms516 KiB
17Time limit exceeded0/1586ms564 KiB
18Wrong answer0/113ms564 KiB
19Time limit exceeded0/1600ms560 KiB
20Time limit exceeded0/1600ms564 KiB
21Time limit exceeded0/1600ms568 KiB
22Time limit exceeded0/1582ms568 KiB
23Time limit exceeded0/1583ms748 KiB
24Time limit exceeded0/1586ms560 KiB
25Wrong answer0/24ms316 KiB
26Time limit exceeded0/2600ms416 KiB
27Time limit exceeded0/2592ms380 KiB
28Time limit exceeded0/1584ms564 KiB
29Time limit exceeded0/2586ms564 KiB
30Time limit exceeded0/1600ms612 KiB
31Time limit exceeded0/1587ms564 KiB
32Wrong answer0/2201ms500 KiB
33Time limit exceeded0/2588ms712 KiB
34Time limit exceeded0/1600ms752 KiB
35Time limit exceeded0/2575ms564 KiB
36Time limit exceeded0/2600ms768 KiB
37Time limit exceeded0/2579ms748 KiB
38Time limit exceeded0/2587ms740 KiB
39Wrong answer0/121ms404 KiB