Submission details
Task:Lista
Sender:worst
Submission time:2026-01-17 16:57:31 +0200
Language:C++ (C++20)
Status:READY
Result:12
Feedback
groupverdictscore
#10
#20
#3ACCEPTED12
#40
#50
#60
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 3, 4, 5, 6details
#20.00 s1, 4, 5, 6details
#3ACCEPTED0.00 s1, 2, 4, 5, 6details
#4ACCEPTED0.00 s1, 2, 4, 5, 6details
#50.00 s1, 2, 4, 5, 6details
#6ACCEPTED0.00 s1, 3, 4, 5, 6details
#7ACCEPTED0.00 s1, 4, 5, 6details
#8ACCEPTED0.00 s1, 4, 5, 6details
#90.00 s1, 4, 5, 6details
#10ACCEPTED0.00 s1, 2, 4, 5, 6details
#11ACCEPTED0.00 s1, 4, 5, 6details
#12ACCEPTED0.00 s1, 4, 5, 6details
#13ACCEPTED0.00 s1, 4, 5, 6details
#140.18 s2, 6details
#150.21 s2, 6details
#160.23 s2, 6details
#170.22 s2, 6details
#18ACCEPTED0.16 s2, 6details
#19ACCEPTED0.15 s2, 6details
#20ACCEPTED0.00 s1, 3, 4, 5, 6details
#21ACCEPTED0.18 s3, 6details
#22ACCEPTED0.21 s3, 6details
#23ACCEPTED0.23 s3, 6details
#24ACCEPTED0.23 s3, 6details
#25ACCEPTED0.15 s3, 6details
#26ACCEPTED0.16 s3, 6details
#270.01 s4, 6details
#280.01 s4, 6details
#290.01 s4, 6details
#30ACCEPTED0.01 s2, 4, 6details
#31ACCEPTED0.01 s4, 6details
#32ACCEPTED0.01 s4, 6details
#330.12 s5, 6details
#340.13 s5, 6details
#350.20 s5, 6details
#36ACCEPTED0.11 s2, 5, 6details
#370.16 s5, 6details
#380.22 s6details
#390.22 s6details
#400.38 s6details
#41ACCEPTED0.12 s2, 5, 6details
#420.16 s5, 6details
#43ACCEPTED0.00 s1, 3, 4, 5, 6details
#440.00 s1, 2, 4, 5, 6details
#450.00 s1, 4, 5, 6details

Code

#include <bits/stdc++.h>
 
using namespace std;
 
 
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    set<pair<int, int>> sp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sp.insert({a[i], n - 1 - i});
    }
    
    vector<bool> changing(n, false);

    int last = -1;

    for (int i = 0; i < n; i++) {
        if (k <= 1) {
            break;
        }
        if (k >= 2) {
            if (a[i] > (*sp.begin()).first) {
                if (!changing[(*sp.begin()).second]) {
                    k--;
                }

                if (!changing[i]) {
                    k--;
                }

                changing[i] = true;
                changing[n - 1 - (*sp.begin()).second] = true;

                last = max(last, i);
                last = max(last, n - 1 - (*sp.begin()).second);

                sp.erase({a[i], i});
                sp.insert({a[i], n - 1 - (*sp.begin()).second});

                swap(a[i], a[n - 1 - (*sp.begin()).second]);

                sp.erase(sp.begin());
            }
        }
    }

    bool f = true;

    for (int i = 0; i < last; i++) {
        if (a[i] > a[last]){
            swap(a[i], a[last]);
            f = false;
            break;
        }
    }

    if (f) {
        for (pair<int, int> p : sp) {
            if (p.first < a[last] && n - 1 - p.second > last) {
                swap(a[last], a[n - 1 - p.second]);
            }
        }
    }
 
    for (int i = 0; i < n; i++) {
        cout << a[i] << ' ';
    }
    cout << '\n';
}
 
int main() {
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Test details

Test 1 (public)

Group: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
6 3
6 5 1 4 1 3

correct output
1 5 1 4 3 6

user output
1 5 1 4 3 6 

Test 2 (public)

Group: 1, 4, 5, 6

Verdict:

input
4 4
1 2 3 4

correct output
1 2 3 4

user output
2 1 3 4 

Feedback: Incorrect character on line 1 col 1: expected "1", got "2"

Test 3

Group: 1, 2, 4, 5, 6

Verdict: ACCEPTED

input
2 2
2 1

correct output
1 2

user output
1 2 

Test 4

Group: 1, 2, 4, 5, 6

Verdict: ACCEPTED

input
10 2
6 6 6 6 6 6 6 6 6 6

correct output
6 6 6 6 6 6 6 6 6 6

user output
6 6 6 6 6 6 6 6 6 6 

Test 5

Group: 1, 2, 4, 5, 6

Verdict:

input
10 2
2 5 10 1 8 6 4 7 3 9

correct output
1 5 10 2 8 6 4 7 3 9

user output
1 2 10 5 8 6 4 7 3 9 

Feedback: Incorrect character on line 1 col 3: expected "5", got "2"

Test 6

Group: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
10 3
6 9 2 7 5 4 9 9 10 8

correct output
2 6 9 7 5 4 9 9 10 8

user output
2 6 9 7 5 4 9 9 10 8 

Test 7

Group: 1, 4, 5, 6

Verdict: ACCEPTED

input
10 4
3 4 2 9 5 1 5 6 10 8

correct output
1 2 3 9 5 4 5 6 10 8

user output
1 2 3 9 5 4 5 6 10 8 

Test 8

Group: 1, 4, 5, 6

Verdict: ACCEPTED

input
10 7
8 10 6 4 5 3 1 9 2 9

correct output
1 2 3 4 5 6 8 9 9 10

user output
1 2 3 4 5 6 8 9 9 10 

Test 9

Group: 1, 4, 5, 6

Verdict:

input
10 10
8 5 7 7 6 9 5 1 3 4

correct output
1 3 4 5 5 6 7 7 8 9

user output
1 6 4 5 3 5 7 7 9 8 

Feedback: Incorrect character on line 1 col 3: expected "3", got "6"

Test 10

Group: 1, 2, 4, 5, 6

Verdict: ACCEPTED

input
10 2
1 2 3 4 5 6 7 8 9 10

correct output
1 2 3 4 5 6 7 8 9 10

user output
1 2 3 4 5 6 7 8 9 10 

Test 11

Group: 1, 4, 5, 6

Verdict: ACCEPTED

input
10 9
10 9 8 7 6 5 4 3 2 1

correct output
1 2 3 4 6 5 7 8 9 10

user output
1 2 3 4 6 5 7 8 9 10 

Test 12

Group: 1, 4, 5, 6

Verdict: ACCEPTED

input
10 10
10 9 8 7 6 5 4 3 2 1

correct output
1 2 3 4 5 6 7 8 9 10

user output
1 2 3 4 5 6 7 8 9 10 

Test 13

Group: 1, 4, 5, 6

Verdict: ACCEPTED

input
9 8
9 8 7 6 5 4 3 2 1

correct output
1 2 3 4 5 6 7 8 9

user output
1 2 3 4 5 6 7 8 9 

Test 14

Group: 2, 6

Verdict:

input
200000 2
176369 57172 92603 196271 1967...

correct output
1155 57172 92603 196271 196768...

user output
1155 57172 92603 176369 196768...

Feedback: Incorrect character on line 1 col 19: expected "196271", got "176369"

Test 15

Group: 2, 6

Verdict:

input
200000 2
188653 156245 40967 173336 185...

correct output
57 156245 40967 173336 185896 ...

user output
57 156245 40967 173336 185896 ...

Feedback: Incorrect character on line 1 col 186: expected "199449", got "188653"

Test 16

Group: 2, 6

Verdict:

input
200000 2
170455 14692 60230 38375 31037...

correct output
20 14692 60230 38375 31037 395...

user output
20 14692 60230 38375 31037 395...

Feedback: Incorrect character on line 1 col 58: expected "180877", got "170455"

Test 17

Group: 2, 6

Verdict:

input
200000 2
59289 119695 145821 16906 1149...

correct output
1 119695 145821 16906 114932 1...

user output
1 59289 145821 16906 114932 16...

Feedback: Incorrect character on line 1 col 3: expected "119695", got "59289"

Test 18

Group: 2, 6

Verdict: ACCEPTED

input
200000 2
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 19

Group: 2, 6

Verdict: ACCEPTED

input
200000 2
200000 199999 199998 199997 19...

correct output
1 199999 199998 199997 199996 ...

user output
1 199999 199998 199997 199996 ...

Test 20

Group: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
3 3
3 2 1

correct output
1 2 3

user output
1 2 3 

Test 21

Group: 3, 6

Verdict: ACCEPTED

input
200000 3
66357 7587 176209 27489 170275...

correct output
390 7587 66357 27489 170275 31...

user output
390 7587 66357 27489 170275 31...

Test 22

Group: 3, 6

Verdict: ACCEPTED

input
200000 3
93946 193045 25177 150263 1482...

correct output
205 93946 25177 150263 148229 ...

user output
205 93946 25177 150263 148229 ...

Test 23

Group: 3, 6

Verdict: ACCEPTED

input
200000 3
81262 22620 25235 22620 10144 ...

correct output
6 22620 25235 22620 10144 2614...

user output
6 22620 25235 22620 10144 2614...

Test 24

Group: 3, 6

Verdict: ACCEPTED

input
200000 3
62925 65929 74691 187894 13817...

correct output
1 62925 74691 187894 138170 15...

user output
1 62925 74691 187894 138170 15...

Test 25

Group: 3, 6

Verdict: ACCEPTED

input
200000 3
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 26

Group: 3, 6

Verdict: ACCEPTED

input
200000 3
200000 199999 199998 199997 19...

correct output
1 199999 199998 199997 199996 ...

user output
1 199999 199998 199997 199996 ...

Test 27

Group: 4, 6

Verdict:

input
2000 100
1468 510 463 644 1429 1108 153...

correct output
1 2 3 4 5 6 7 8 9 10 11 13 14 ...

user output
1 2 3 4 5 6 7 8 9 10 11 13 14 ...

Feedback: Incorrect character on line 1 col 142: expected "95", got "53"

Test 28

Group: 4, 6

Verdict:

input
2000 1000
1246 1024 680 1448 504 921 976...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 890 6 7 8 9 10 11 855 ...

Feedback: Incorrect character on line 1 col 9: expected "5", got "890"

Test 29

Group: 4, 6

Verdict:

input
2000 1900
461 1257 1198 1876 651 1930 15...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1097 1737 1279 1838 1444 6 165...

Feedback: Incorrect character on line 1 col 2: expected "1", got "1097"

Test 30

Group: 2, 4, 6

Verdict: ACCEPTED

input
2000 2
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 31

Group: 4, 6

Verdict: ACCEPTED

input
2000 597
2000 1999 1998 1997 1996 1995 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 32

Group: 4, 6

Verdict: ACCEPTED

input
2000 2000
2000 1999 1998 1997 1996 1995 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 33

Group: 5, 6

Verdict:

input
200000 100
8 4 2 6 7 2 9 2 10 9 4 1 1 3 1...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Feedback: Incorrect character on line 1 col 119: expected "10", got "8"

Test 34

Group: 5, 6

Verdict:

input
200000 10000
5 7 2 6 1 9 7 2 4 10 1 4 4 1 9...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Feedback: Incorrect character on line 1 col 11113: expected "6", got "5"

Test 35

Group: 5, 6

Verdict:

input
200000 190000
8 3 5 5 7 8 10 10 8 10 2 2 2 8...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 5 7 9 1 1 9 1 1 1 5 10 10 1 ...

Feedback: Incorrect character on line 1 col 3: expected "1", got "5"

Test 36

Group: 2, 5, 6

Verdict: ACCEPTED

input
200000 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 37

Group: 5, 6

Verdict:

input
200000 200000
10 10 10 10 10 10 10 10 10 10 ...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Feedback: Incorrect character on line 1 col 79795: expected "2", got "9"

Test 38

Group: 6

Verdict:

input
200000 100
151203 41607 101924 180578 132...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Feedback: Incorrect character on line 1 col 142: expected "111260", got "66467"

Test 39

Group: 6

Verdict:

input
200000 10000
172851 90759 102500 164610 200...

correct output
1 2 3 4 5 6 7 8 8 9 10 11 11 1...

user output
1 2 3 4 5 6 7 8 8 9 10 11 11 1...

Feedback: Incorrect character on line 1 col 515: expected "143", got "90155"

Test 40

Group: 6

Verdict:

input
200000 190000
176771 53238 75539 184219 9404...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 92563 137406 4 147414 112019...

Feedback: Incorrect character on line 1 col 3: expected "2", got "92563"

Test 41

Group: 2, 5, 6

Verdict: ACCEPTED

input
200000 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 42

Group: 5, 6

Verdict:

input
200000 200000
10 10 10 10 10 10 10 10 10 10 ...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Feedback: Incorrect character on line 1 col 119757: expected "4", got "7"

Test 43

Group: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
10 3
8 5 5 8 8 10 10 10 6 3

correct output
3 5 5 8 8 8 10 10 6 10

user output
3 5 5 8 8 8 10 10 6 10 

Test 44

Group: 1, 2, 4, 5, 6

Verdict:

input
10 2
1 1 2 5 2 7 1 2 4 2

correct output
1 1 1 5 2 7 2 2 4 2

user output
1 1 1 2 2 7 5 2 4 2 

Feedback: Incorrect character on line 1 col 7: expected "5", got "2"

Test 45

Group: 1, 4, 5, 6

Verdict:

input
10 4
1 1 2 5 2 7 1 2 4 2

correct output
1 1 1 2 2 5 7 2 4 2

user output
1 2 1 1 2 7 5 2 4 2 

Feedback: Incorrect character on line 1 col 3: expected "1", got "2"