CSES - Datatähti 2023 loppu - Results
Submission details
Task:Kulut
Sender:stpn129
Submission time:2023-01-21 13:30:26 +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
#11ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:68:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    for (int i = 0; i < res.size(); ++i) {
      |                    ~~^~~~~~~~~~~~

Code

#include<bits/stdc++.h>
#define int long long

using namespace std;

void init_code(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}

bool cmp (pair<int, int> a, pair<int, int> b) {
   return a.second < b.second;
}

void solve() {
   int n;
   cin >> n;

   vector<int> p(4);

   int total = 0;
   for (int i = 0; i < n; ++i) {
      char t;
      int paid;      

      cin >> t >> paid;

      int x = t - 'A';

      p[x] += paid;
      total += paid;
   }

   int mid = total / 4;

   vector<pair<int, int>> s(4);
   for (int i = 0; i < 4; ++i) {
      s[i] = {i, p[i]};
   }

   vector<pair<pair<int, int>, int>> res;
   int check = 0;
   while (!check) {
      int c = 0;
      for (int i = 0; i < 4; ++i) {
         c += (s[i].second == mid);
      }
      if (c == 4) {
         check = 1;
         break;
      }
      sort(s.rbegin(), s.rend(), cmp);
      for (int i = 1; i < 4; ++i) {
         if (s[i].second >= mid) {
            continue;
         }
         int x = mid - s[i].second;
         res.push_back({{s[i].first, s[0].first}, x});
         s[0].second -= x;
         s[i].second += x;
      }
   }

   for (int i = 0; i < res.size(); ++i) {
      char a = res[i].first.first + 'A', b = res[i].first.second + 'A';
      int c = res[i].second;
      cout << a << ' ' << b << ' ' << c << '\n';
   }
}

signed main() {
   init_code();
   int t = 1; 
   //cin >> t;
   while(t--){
      solve();
   }
   return 0;
}

/*
cubbli-guest@dx5-cs-b221-09:~$ cd Code
cubbli-guest@dx5-cs-b221-09:~/Code$ ls
code  code.cpp  input.txt  output.txt
cubbli-guest@dx5-cs-b221-09:~/Code$ g++ code.cpp -o code
cubbli-guest@dx5-cs-b221-09:~/Code$ ./code
Segmentation fault (core dumped)
cubbli-guest@dx5-cs-b221-09:~/Code$ 


*/

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

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
D C 1776
B C 2424
C A 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
C B 107
A B 1131
B D 297

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

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

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
B D 767
C D 839
D A 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
C B 2208
D B 2920
B A 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
A C 24
D C 2252
C B 560

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

Test 10

Verdict:

input
1
A 100

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

user output
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
(empty)