CSES - Datatähti 2023 loppu - Results
Submission details
Task:Kulut
Sender:xenial
Submission time:2023-01-21 13:33:59 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:55:25: warning: 'amt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |         ans.pb(make_pair(xd, amt));
      |                ~~~~~~~~~^~~~~~~~~

Code

#include <bits/stdc++.h>
#define pb push_back
#define vi vector<int>
#define sz size
using namespace std;

int N, p[4], total;

int main() {
    ios_base::sync_with_stdio(false);

    cin >> N;

    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        int s;
        cin >> s;
        p[c - 'A'] += s;
        total += s;
    }

    int target = total / 4;

    vector<pair<pair<char, char>, int>> ans;

    stack<int> pos, neg;

    for (int i = 0; i < 4; i++) {
        if (p[i] > target) pos.push(i);
        else if (p[i] < target) neg.push(i);
    }

    while (true) {
        pair<char,char> xd = make_pair('A' + pos.top(), 'A' + neg.top());
        int amt;

        int pdiff = abs(p[pos.top()] - target);
        int ndiff = abs(p[neg.top()] - target);

        if (pdiff == ndiff) {
            pos.pop();
            neg.pop();
            amt = pdiff;
        } else if (pdiff > ndiff) {
            neg.pop();
            amt = ndiff;
            p[pos.top()] -= amt;
        } else if (pdiff < ndiff) {
            pos.pop();
            amt = pdiff;
            p[neg.top()] += amt;
        }

        ans.pb(make_pair(xd, amt));

        if (pos.sz() == 0 && neg.sz() == 0) {
            break;
        }
    }

    cout << ans.sz() << endl;
    for (auto r : ans) {
        cout << r.first.first << " " << r.first.second << " " << r.second << endl;
    }

    return 0;
}

Test details

Test 1

Verdict:

input
100
C 224
D 4
D 624
D 64
...

correct output
3
A B 630
C B 1636
C D 1470

user output
3
D C 1470
B C 1636
B A 630

Test 2

Verdict:

input
100
D 768
B 608
A 116
C 80
...

correct output
3
B A 756
B C 1668
D C 1776

user output
3
C D 1776
C B 1668
A B 756

Test 3

Verdict:

input
100
B 184
C 840
D 648
A 876
...

correct output
3
A B 1131
B C 190
C D 297

user output
3
D C 107
D A 190
B A 941

Test 4

Verdict:

input
100
C 560
D 664
D 632
C 944
...

correct output
3
B A 3230
C B 2572
D C 1594

user output
3
A D 1594
A C 978
A B 658

Test 5

Verdict:

input
100
B 20
A 664
D 504
A 248
...

correct output
3
A B 138
B C 652
C D 350

user output
3
D B 350
C B 164
C A 138

Test 6

Verdict:

input
100
B 204
D 520
C 500
C 256
...

correct output
3
B A 285
B C 482
C D 1321

user output
3
D C 839
D B 482
A B 285

Test 7

Verdict:

input
100
B 672
B 840
A 712
C 640
...

correct output
3
B A 324
C B 5128
D C 2920

user output
3
B D 2920
B C 1884
A C 324

Test 8

Verdict:

input
100
C 860
D 732
A 952
C 940
...

correct output
3
A B 24
C B 536
D C 2252

user output
3
C D 1716
B D 536
B A 24

Test 9

Verdict:

input
100
C 84
A 592
B 840
C 708
...

correct output
3
A B 115
B C 1746
D C 3791

user output
3
C D 3791
C B 1631
C A 115

Test 10

Verdict:

input
1
A 100

correct output
3
B A 75
C B 50
D C 25

user output
3
A D 25
A C 25
A B 25

Test 11

Verdict:

input
4
A 25
B 25
C 25
D 25

correct output
0

user output
(empty)