Submission details
Task:Järjestys
Sender:Lieska
Submission time:2025-09-05 20:55:04 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.00 s1, 4, 5details
#20.00 s1, 4, 5details
#30.00 s1, 4, 5details
#40.00 s1, 4, 5details
#50.00 s1, 4, 5details
#60.00 s1, 2, 4, 5details
#70.01 s1, 3, 4, 5details
#80.00 s1, 4, 5details
#90.00 s2, 4, 5details
#100.00 s3, 4, 5details
#110.04 s4, 5details
#120.01 s4, 5details
#130.01 s4, 5details
#140.02 s4, 5details
#150.30 s2, 5details
#160.00 s3, 5details
#170.22 s5details
#180.16 s5details
#190.34 s5details
#200.32 s5details
#210.18 s5details
#220.00 s5details

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

multiset<pair<int, int>> s;

bool test(int end_point, multiset<pair<int, int>> &s1){
    int diff=0;
    if (s1.size()==0) return true;
    bool not_last = false;
    for (auto u:s1){
        if (u.first%2==1)  diff-=1;
        else diff+=1;
        cout << u.first << " " << diff << " " << end_point << "\n";
        if (diff < -1 && u.first >= end_point) return false;
        if (diff < 0 && u.first < end_point) return false;
        if (u.first > end_point) not_last = true;
    }
    return not_last;
}



int main(){
    
    int t;
    cin >> t;
    for (int i=1; i<=t; ++i){
        int n;
        cin >> n;
        vector<pair<int, int>> v, result;
        for (int j=0; j<n; ++j){
            int a, b;
            cin >> a >> b;
            v.push_back({a,b});
            //We want end points to be before starting points.
            s.insert({2*b, j});
            s.insert({2*a+1,j});
        }
        //cout << "here\n";

        int end_point=0;
        while (true){
            bool okay = false;
            multiset<pair<int, int>> s1;
            pair<int, int> erased1, erased2;
            for (auto u:s) s1.insert(u);
            for (auto u:s){
                if (u.first > end_point && u.first%2==1){
                    int j = u.second;
                    
                    erased1 = {2*v[j].first+1, j};
                    erased2 = {2*v[j].second, j};
                    s1.erase(erased1);
                    s1.erase(erased2);
                    if (test(2*v[j].second, s1) == true){
                        result.push_back({v[j].first, v[j].second});
                        end_point = 2*v[j].second;
                        okay = true;
                        break;
                    }
                    else{
                        s1.insert(erased1);
                        s1.insert(erased2);
                    }
                }
            }
            
            if (okay == true){
                s.erase(erased1);
                s.erase(erased2);
            }
            cout << okay << " " << end_point << "\n";
            for (auto u:s) cout << u.first << " ";
            cout << "\n";
            if (okay == false) break;
            if (s.size()==0) break;
        }
        if (s.size() > 0){
            cout << "NO\n";
            return 0;
        }
        cout << "YES\n";
        for (auto u:result){
            cout << u.first << " " << u.second << "\n";
        }
        
    }
}

Test details

Test 1

Group: 1, 4, 5

Verdict:

input
100
1
74 75
1
100 43
...

correct output
YES
74 75
YES
100 43
YES
...

user output
1 150

YES
74 75
1 86
...
Truncated

Test 2

Group: 1, 4, 5

Verdict:

input
100
2
80 54
51 61
2
...

correct output
YES
51 61
80 54
YES
2 64
...

user output
108 1 122
161 0 122
1 122
108 161 
1 108
...
Truncated

Test 3

Group: 1, 4, 5

Verdict:

input
100
3
3 74
91 45
100 24
...

correct output
YES
3 74
100 24
91 45
YES
...

user output
48 1 148
90 2 148
183 1 148
201 0 148
1 148
...
Truncated

Test 4

Group: 1, 4, 5

Verdict:

input
100
4
88 50
62 41
12 86
...

correct output
YES
12 86
88 50
62 41
66 93
...

user output
82 1 172
100 2 172
125 1 172
133 0 172
177 -1 172
...
Truncated

Test 5

Group: 1, 4, 5

Verdict:

input
100
5
82 80
80 92
5 22
...

correct output
YES
5 22
94 13
82 80
80 92
...

user output
26 1 44
160 2 44
161 1 44
165 0 44
182 1 44
...
Truncated

Test 6

Group: 1, 2, 4, 5

Verdict:

input
100
5
34 38
26 30
1 6
...

correct output
YES
1 6
12 22
26 30
34 38
...

user output
25 -1 12
44 0 12
53 -1 12
60 0 12
69 -1 12
...
Truncated

Test 7

Group: 1, 3, 4, 5

Verdict:

input
100
5
50 40
28 25
51 7
...

correct output
YES
51 7
50 40
47 1
17 11
...

user output
2 1 22
14 2 22
50 3 22
57 2 22
80 3 22
...
Truncated

Test 8

Group: 1, 4, 5

Verdict:

input
100
5
2 2
2 1
1 1
...

correct output
YES
1 2
2 1
2 1
1 1
...

user output
2 1 2
2 2 2
3 1 2
4 2 2
4 3 2
...
Truncated

Test 9

Group: 2, 4, 5

Verdict:

input
100
100
175870020 296379324
248160539 883842002
21934885 781732852
...

correct output
NO
YES
4976156 6890135
10553287 11923223
14617057 17728163
...

user output
6464065 -1 1700768524
807327 -1 1083486216
807327 -1 1573440354
807327 -1 901022032
807327
...
Truncated

Test 10

Group: 3, 4, 5

Verdict:

input
100
100
447597377 314433951
700232436 691277009
937268439 708165426
...

correct output
YES
998963839 391778929
995772196 257222033
995754704 553123757
994629465 247775824
...

user output
(empty)

Test 11

Group: 4, 5

Verdict:

input
100
100
1 1
1 2
2 1
...

correct output
YES
1 2
2 1
1 2
2 2
...

user output
2 1 2
2 2 2
2 3 2
2 4 2
2 5 2
...
Truncated

Test 12

Group: 4, 5

Verdict:

input
100
100
7 1
6 3
10 9
...

correct output
YES
6 7
7 8
9 10
10 10
...

user output
2 1 18
2 2 18
2 3 18
2 4 18
2 5 18
...
Truncated

Test 13

Group: 4, 5

Verdict:

input
100
100
51 5
85 77
91 84
...

correct output
YES
100 24
100 25
100 3
100 6
...

user output
2 1 142
2 2 142
4 3 142
4 4 142
6 5 142
...
Truncated

Test 14

Group: 4, 5

Verdict:

input
100
100
823828194 863717310
593641073 340054211
420481158 965069109
...

correct output
YES
999289319 634855378
996775156 433726648
983657502 55234695
981890636 112877413
...

user output
3339358 1 1155042698
13435180 2 1155042698
30942008 3 1155042698
38205788 4 1155042698
470
...
Truncated

Test 15

Group: 2, 5

Verdict:

input
100
500
88724450 89315226
266915464 267648621
189301651 189661541
...

correct output
YES
764920 1459946
1936195 2832987
3691481 4085931
4991808 5840928
...

user output
3872391 -1 2919892
5665974 0 2919892
7382963 -1 2919892
8171862 0 2919892
9983617 -1 29198
...
Truncated

Test 16

Group: 3, 5

Verdict:

input
100
500
763682761 317584504
756010800 260162861
435911339 78070399
...

correct output
YES
998768285 3307355
998714926 628486754
997115613 820932481
993320616 554600893
...

user output
(empty)

Test 17

Group: 5

Verdict:

input
100
500
2 2
2 1
1 2
...

correct output
YES
1 2
2 2
2 1
1 2
...

user output
2 1 4
2 2 4
2 3 4
2 4 4
2 5 4
...
Truncated

Test 18

Group: 5

Verdict:

input
100
500
10 6
10 10
9 10
...

correct output
YES
2 3
3 4
4 5
5 6
...

user output
2 1 10
2 2 10
2 3 10
2 4 10
2 5 10
...
Truncated

Test 19

Group: 5

Verdict:

input
100
500
85 87
89 70
70 92
...

correct output
YES
96 97
100 67
100 10
100 97
...

user output
2 1 54
2 2 54
2 3 54
2 4 54
2 5 54
...
Truncated

Test 20

Group: 5

Verdict:

input
100
500
861154169 119512584
569086662 606567153
288230434 322196278
...

correct output
YES
999945324 969534372
999738857 240617694
999244114 722161553
999207839 557351400
...

user output
1746630 1 1415617496
7487928 2 1415617496
13905236 3 1415617496
14001122 4 1415617496
1484
...
Truncated

Test 21

Group: 5

Verdict:

input
100
500
116439250 401518028
280329609 193466222
674040956 209050570
...

correct output
NO
YES
773701149 773852119
987509190 315670966
977413249 510418200
...

user output
876046 1 3432406
1112840 2 3432406
1858288 3 3432406
2487630 4 3432406
2988754 5 3432406
...
Truncated

Test 22

Group: 5

Verdict:

input
100
500
934181189 942499518
684836806 395802802
957884803 570946201
...

correct output
YES
999772640 505132174
999111650 140844643
999028633 888134186
999020109 291046771
...

user output
(empty)