CSES - Datatähti 2023 loppu - Results
Submission details
Task:Kulut
Sender:Turtleb01
Submission time:2023-01-21 13:42:19 +0200
Language:Node.js
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.11 sdetails
#2ACCEPTED0.11 sdetails
#3ACCEPTED0.11 sdetails
#4ACCEPTED0.11 sdetails
#5ACCEPTED0.11 sdetails
#6ACCEPTED0.11 sdetails
#7ACCEPTED0.11 sdetails
#8ACCEPTED0.11 sdetails
#9ACCEPTED0.11 sdetails
#10ACCEPTED0.11 sdetails
#11ACCEPTED0.11 sdetails

Code

const fs = require("fs");

const input = fs.readFileSync(0, {encoding:"utf-8"}).split("\n");

const payments = parseInt(input[0]);

let people = Array(4).fill(0);

const letters = ["A","B","C","D"];

for(i=1;i<=payments;i++) {
    [letter,amount] = input[i].split(" ");
    people[letters.indexOf(letter)]+=parseInt(amount);
}

// console.log(...people);

let average = people.reduce((v,e)=>v+e,0)/4;

people = people.map((e,i)=>[average-e,i]);

let events = [];

for(i=0;i<3;i++) {
    people = people.sort((a,b)=>b[0]-a[0]);
//     console.log(people);
    events.push([
        people[0][1],
        people[3-i][1],
        people[0][0]
    ]);
    people[3-i][0]+=people[0][0];
    people.shift();
}

events=events.filter(e=>e[2]!=0);

console.log(events.length.toString())

console.log(events.map(e=>`${letters[e[0]]} ${letters[e[1]]} ${e[2]}`).join("\n"));

Test details

Test 1

Verdict: ACCEPTED

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
C B 3106
B D 840
A D 630

Test 2

Verdict: ACCEPTED

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
B C 2424
D C 1776
C A 756

Test 3

Verdict: ACCEPTED

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
A B 1131
B D 190
C D 107

Test 4

Verdict: ACCEPTED

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
D A 1594
C A 978
B A 658

Test 5

Verdict: ACCEPTED

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
B D 514
D C 164
A C 138

Test 6

Verdict: ACCEPTED

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
C D 839
B D 767
D A 285

Test 7

Verdict: ACCEPTED

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
D B 2920
C B 2208
B A 324

Test 8

Verdict: ACCEPTED

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
D C 2252
C B 536
A B 24

Test 9

Verdict: ACCEPTED

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
D C 3791
B C 1631
A C 115

Test 10

Verdict: ACCEPTED

input
1
A 100

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

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

Test 11

Verdict: ACCEPTED

input
4
A 25
B 25
C 25
D 25

correct output
0

user output
0