QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63298#1866. DecompositionlmeowdnAC ✓312ms11376kbC++171.2kb2022-11-21 16:28:222022-11-21 16:28:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-21 16:28:22]
  • 评测
  • 测评结果:AC
  • 用时:312ms
  • 内存:11376kb
  • [2022-11-21 16:28:22]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define eb emplace_back
#define y1 yylyylyylyyl
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef __int128 lll;
 
long long read() {
    long long res=0, w=1; char c=getchar();
    while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
    while(isdigit(c)) {res=res*10+c-48, c=getchar();}
    return res*w;
}

int T,n,m;

signed main() {
    T=read();
    rep(t,1,T) {
        n=read(), m=read();
        vector<int>c;
        rep(k,1,n/2) {
            c.eb(n); n--;
            int x=k+1, y=k;
            rep(j,1,n/2) {
                c.eb(x), c.eb(y);
                y--, x++;
                if(y==0) y=n;
                if(x==n+1) x=1;
            }
            n++;
        }
        c.eb(n);
        int pos=0;
        printf("Case #%lld:\n",t);
        rep(i,1,m) {
            int l=read()+1;
            while(l--) printf("%lld ",c[pos++]);
            puts(""); pos--;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3424kb

input:

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

output:

Case #1:
5 2 1 
1 3 
3 4 
4 5 3 
3 2 4 
4 1 5 
Case #2:
7 2 
2 1 
1 3 6 4 5 
5 7 3 2 
2 4 1 5 6 
6 7 
7 4 3 5 
5 2 6 1 7 
Case #3:
5 2 
2 1 
1 3 
3 4 
4 5 
5 3 
3 2 
2 4 
4 1 
1 5 

result:

ok OK, 3 cases

Test #2:

score: 0
Accepted
time: 37ms
memory: 3484kb

input:

5000
13 12
5 8 9 7 5 4 10 10 7 9 2 2
7 13
2 2 1 2 2 2 3 1 1 1 2 1 1
11 16
1 1 5 4 6 2 5 1 5 8 1 1 7 3 4 1
13 17
4 1 9 1 8 1 7 6 4 8 2 8 5 8 4 1 1
5 6
1 2 1 2 2 2
9 9
5 4 5 4 5 1 6 1 5
17 23
4 9 1 10 5 8 8 7 4 11 2 4 6 3 6 7 11 3 10 7 4 5 1
13 14
10 9 1 1 1 10 3 8 8 10 3 3 10 1
7 8
4 1 4 1 4 3 2 2
19...

output:

Case #1:
13 2 1 3 12 4 
4 11 5 10 6 9 7 8 13 
13 3 2 4 1 5 12 6 11 7 
7 10 8 9 13 4 3 5 
5 2 6 1 7 12 
12 8 11 9 10 
10 13 5 4 6 3 7 2 8 1 9 
9 12 10 11 13 6 5 7 4 8 3 
3 9 2 10 1 11 12 13 
13 7 6 8 5 9 4 10 3 11 
11 2 12 
12 1 13 
Case #2:
7 2 1 
1 3 6 
6 4 
4 5 7 
7 3 2 
2 4 1 
1 5 6 7 
7 4 
4 3 
...

result:

ok OK, 5000 cases

Test #3:

score: 0
Accepted
time: 28ms
memory: 3480kb

input:

2000
27 44
5 15 4 6 7 14 9 2 1 24 9 4 12 6 13 23 7 3 21 2 5 2 3 20 8 12 10 21 3 1 6 8 8 4 5 3 19 1 10 7 4 1 1 2
29 31
25 8 18 22 7 7 25 9 26 25 6 11 20 1 7 9 11 14 23 20 1 13 16 1 22 23 14 6 13 1 2
27 27
16 24 6 12 3 3 22 2 24 12 6 10 18 14 8 21 20 14 15 4 23 20 2 14 11 23 4
29 39
15 19 3 7 1 13 20 ...

output:

Case #1:
27 2 1 3 26 4 
4 25 5 24 6 23 7 22 8 21 9 20 10 19 11 18 
18 12 17 13 16 
16 14 15 27 3 2 4 
4 1 5 26 6 25 7 24 
24 8 23 9 22 10 21 11 20 12 19 13 18 14 17 
17 15 16 27 4 3 5 2 6 1 
1 7 26 
26 8 
8 25 9 24 10 23 11 22 12 21 13 20 14 19 15 18 16 17 27 5 4 6 3 7 2 
2 8 1 9 26 10 25 11 24 12 
...

result:

ok OK, 2000 cases

Test #4:

score: 0
Accepted
time: 20ms
memory: 3452kb

input:

800
9 11
5 5 4 1 1 5 5 6 2 1 1
11 14
5 7 5 1 3 3 6 8 3 7 2 3 1 1
19 22
14 10 8 2 9 12 13 2 6 5 8 5 5 1 12 1 10 13 10 2 14 9
9 9
6 5 3 4 3 4 4 6 1
5 7
2 1 1 2 1 2 1
5 7
1 2 2 2 1 1 1
31 29
20 8 18 13 1 24 12 9 12 19 24 25 21 23 6 27 12 10 17 19 23 26 23 5 28 14 11 2 13
49 48
42 46 45 12 5 24 16 28 40...

output:

Case #1:
9 2 1 3 8 4 
4 7 5 6 9 3 
3 2 4 1 5 
5 8 
8 6 
6 7 9 4 3 5 
5 2 6 1 7 8 
8 9 5 4 6 3 7 
7 2 8 
8 1 
1 9 
Case #2:
11 2 1 3 10 4 
4 9 5 8 6 7 11 3 
3 2 4 1 5 10 
10 6 
6 9 7 8 
8 11 4 3 
3 5 2 6 1 7 10 
10 8 9 11 5 4 6 3 7 
7 2 8 1 
1 9 10 11 6 5 7 4 
4 8 3 
3 9 2 10 
10 1 
1 11 
Case #3:
19...

result:

ok OK, 800 cases

Test #5:

score: 0
Accepted
time: 33ms
memory: 3636kb

input:

200
23 26
6 17 15 16 8 5 3 20 8 17 16 8 10 10 10 10 14 1 16 12 7 6 2 4 10 2
47 45
40 15 13 24 37 4 37 8 27 44 12 11 38 19 41 26 22 33 13 26 20 40 39 37 21 16 32 14 9 8 32 36 43 28 29 4 26 38 23 34 5 23 17 16 1
11 12
4 6 7 7 8 4 8 3 1 2 3 2
89 89
57 9 68 20 45 8 78 59 16 83 72 8 42 39 76 76 28 72 46 ...

output:

Case #1:
23 2 1 3 22 4 21 
21 5 20 6 19 7 18 8 17 9 16 10 15 11 14 12 13 23 
23 3 2 4 1 5 22 6 21 7 20 8 19 9 18 10 
10 17 11 16 12 15 13 14 23 4 3 5 2 6 1 7 22 
22 8 21 9 20 10 19 11 18 
18 12 17 13 16 14 
14 15 23 5 
5 4 6 3 7 2 8 1 9 22 10 21 11 20 12 19 13 18 14 17 15 
15 16 23 6 5 7 4 8 3 
3 9 ...

result:

ok OK, 200 cases

Test #6:

score: 0
Accepted
time: 30ms
memory: 4632kb

input:

8
123 123
11 68 57 31 101 57 58 24 104 69 103 1 3 32 74 103 13 86 90 112 64 109 25 68 60 102 89 50 112 37 53 93 24 115 93 21 56 82 80 13 71 54 94 16 6 57 20 39 54 76 48 57 75 35 63 11 86 102 32 20 65 15 81 15 98 14 102 57 92 94 46 104 56 60 57 120 31 114 23 111 15 96 68 93 50 26 114 79 103 59 106 60...

output:

Case #1:
123 2 1 3 122 4 121 5 120 6 119 7 
7 118 8 117 9 116 10 115 11 114 12 113 13 112 14 111 15 110 16 109 17 108 18 107 19 106 20 105 21 104 22 103 23 102 24 101 25 100 26 99 27 98 28 97 29 96 30 95 31 94 32 93 33 92 34 91 35 90 36 89 37 88 38 87 39 86 40 85 41 
41 84 42 83 43 82 44 81 45 80 46...

result:

ok OK, 8 cases

Test #7:

score: 0
Accepted
time: 64ms
memory: 10520kb

input:

2
931 941
37 625 158 286 652 892 205 242 367 627 914 33 501 700 280 117 693 593 389 547 807 758 160 565 24 601 784 551 322 749 463 504 681 221 8 857 511 554 45 797 828 538 779 876 868 475 607 43 161 692 514 687 717 420 610 570 389 112 587 551 890 101 128 371 621 186 263 926 332 130 21 898 311 436 32...

output:

Case #1:
931 2 1 3 930 4 929 5 928 6 927 7 926 8 925 9 924 10 923 11 922 12 921 13 920 14 919 15 918 16 917 17 916 18 915 19 914 20 
20 913 21 912 22 911 23 910 24 909 25 908 26 907 27 906 28 905 29 904 30 903 31 902 32 901 33 900 34 899 35 898 36 897 37 896 38 895 39 894 40 893 41 892 42 891 43 890...

result:

ok OK, 2 cases

Test #8:

score: 0
Accepted
time: 12ms
memory: 5336kb

input:

2
57 60
24 19 36 48 4 43 19 52 8 52 6 17 10 19 18 41 20 36 4 41 38 34 24 26 29 48 15 37 10 7 4 8 16 43 8 9 27 38 12 19 52 31 9 54 49 15 51 24 43 54 29 46 12 40 17 36 50 12 2 1
643 646
230 5 469 246 610 243 221 411 352 98 56 243 481 622 240 492 349 336 548 102 516 326 468 563 272 363 99 156 468 562 5...

output:

Case #1:
57 2 1 3 56 4 55 5 54 6 53 7 52 8 51 9 50 10 49 11 48 12 47 13 46 
46 14 45 15 44 16 43 17 42 18 41 19 40 20 39 21 38 22 37 23 
23 36 24 35 25 34 26 33 27 32 28 31 29 30 57 3 2 4 1 5 56 6 55 7 54 8 53 9 52 10 51 11 50 12 49 13 48 
48 14 47 15 46 16 45 17 44 18 43 19 42 20 41 21 40 22 39 23 ...

result:

ok OK, 2 cases

Test #9:

score: 0
Accepted
time: 53ms
memory: 7664kb

input:

2
939 935
96 887 857 430 351 403 292 594 392 287 841 710 428 591 389 218 248 134 924 445 162 52 491 820 314 711 207 112 874 201 908 448 799 207 6 690 782 141 749 623 628 466 495 700 861 588 791 93 364 36 834 772 774 619 615 46 358 5 493 382 121 891 71 564 219 201 496 495 883 781 546 394 548 936 643 ...

output:

Case #1:
939 2 1 3 938 4 937 5 936 6 935 7 934 8 933 9 932 10 931 11 930 12 929 13 928 14 927 15 926 16 925 17 924 18 923 19 922 20 921 21 920 22 919 23 918 24 917 25 916 26 915 27 914 28 913 29 912 30 911 31 910 32 909 33 908 34 907 35 906 36 905 37 904 38 903 39 902 40 901 41 900 42 899 43 898 44 ...

result:

ok OK, 2 cases

Test #10:

score: 0
Accepted
time: 37ms
memory: 11176kb

input:

2
763 776
379 463 566 538 49 15 664 613 227 59 631 331 374 87 4 325 559 80 459 107 528 340 427 420 99 171 492 465 572 316 723 598 423 135 14 156 604 99 648 509 657 449 715 50 157 652 701 521 644 529 420 385 173 55 758 649 311 135 744 47 370 488 40 405 722 284 443 676 57 552 283 241 26 449 522 201 10...

output:

Case #1:
763 2 1 3 762 4 761 5 760 6 759 7 758 8 757 9 756 10 755 11 754 12 753 13 752 14 751 15 750 16 749 17 748 18 747 19 746 20 745 21 744 22 743 23 742 24 741 25 740 26 739 27 738 28 737 29 736 30 735 31 734 32 733 33 732 34 731 35 730 36 729 37 728 38 727 39 726 40 725 41 724 42 723 43 722 44 ...

result:

ok OK, 2 cases

Test #11:

score: 0
Accepted
time: 85ms
memory: 3428kb

input:

18181
11 14
7 1 6 2 7 3 2 7 2 4 5 4 4 1
11 10
8 5 6 8 6 4 6 1 7 4
11 13
7 8 7 3 3 7 1 3 1 4 3 6 2
11 14
3 1 5 3 8 1 4 8 4 8 1 5 3 1
11 15
5 3 2 5 1 5 7 8 2 6 4 4 1 1 1
11 11
6 1 7 5 6 7 6 6 4 5 2
11 12
6 3 5 2 5 8 6 3 4 8 4 1
11 12
3 8 4 3 4 7 2 5 6 6 6 1
11 15
5 5 1 2 5 7 6 1 6 5 6 1 3 1 1
11 15
7 ...

output:

Case #1:
11 2 1 3 10 4 9 5 
5 8 
8 6 7 11 3 2 4 
4 1 5 
5 10 6 9 7 8 11 4 
4 3 5 2 
2 6 1 
1 7 10 8 9 11 5 4 
4 6 3 
3 7 2 8 1 
1 9 10 11 6 5 
5 7 4 8 3 
3 9 2 10 1 
1 11 
Case #2:
11 2 1 3 10 4 9 5 8 
8 6 7 11 3 2 
2 4 1 5 10 6 9 
9 7 8 11 4 3 5 2 6 
6 1 7 10 8 9 11 
11 5 4 6 3 
3 7 2 8 1 9 10 
10 ...

result:

ok OK, 18181 cases

Test #12:

score: 0
Accepted
time: 90ms
memory: 3544kb

input:

4700
21 25
6 14 1 10 8 8 18 5 15 9 15 3 4 3 12 12 18 10 4 1 13 6 8 3 4
21 23
9 15 17 10 2 12 12 12 9 6 8 1 4 8 9 6 16 18 2 14 10 8 2
21 21
17 16 5 9 14 8 14 17 7 7 5 14 13 1 10 2 11 12 4 14 10
21 23
16 5 11 10 14 14 1 13 16 6 8 17 3 1 3 1 6 12 9 17 16 9 2
21 27
2 6 9 17 6 11 5 15 3 17 4 13 9 1 4 5 1...

output:

Case #1:
21 2 1 3 20 4 19 
19 5 18 6 17 7 16 8 15 9 14 10 13 11 12 
12 21 
21 3 2 4 1 5 20 6 19 7 18 
18 8 17 9 16 10 15 11 14 
14 12 13 21 4 3 5 2 6 
6 1 7 20 8 19 9 18 10 17 11 16 12 15 13 14 21 5 4 
4 6 3 7 2 8 
8 1 9 20 10 19 11 18 12 17 13 16 14 15 21 6 
6 5 7 4 8 3 9 2 10 1 
1 11 20 12 19 13 1...

result:

ok OK, 4700 cases

Test #13:

score: 0
Accepted
time: 90ms
memory: 3432kb

input:

2000
31 34
5 28 14 25 14 13 10 2 21 24 28 6 4 23 9 5 4 26 18 18 8 7 24 12 21 19 19 10 2 11 7 13 9 6
31 33
20 18 1 26 19 2 5 27 18 18 12 15 28 28 1 12 5 5 5 11 10 9 5 14 26 18 10 23 27 25 17 1 4
31 29
28 18 22 1 4 17 12 23 19 27 12 19 26 27 26 18 6 9 20 16 6 19 17 25 3 12 23 5 5
31 37
9 25 27 12 28 9...

output:

Case #1:
31 2 1 3 30 4 
4 29 5 28 6 27 7 26 8 25 9 24 10 23 11 22 12 21 13 20 14 19 15 18 16 17 31 3 2 
2 4 1 5 30 6 29 7 28 8 27 9 26 10 25 
25 11 24 12 23 13 22 14 21 15 20 16 19 17 18 31 4 3 5 2 6 1 7 30 8 29 
29 9 28 10 27 11 26 12 25 13 24 14 23 15 22 
22 16 21 17 20 18 19 31 5 4 6 3 7 2 
2 8 1...

result:

ok OK, 2000 cases

Test #14:

score: 0
Accepted
time: 90ms
memory: 3508kb

input:

780
51 55
2 9 14 17 31 21 36 21 16 40 32 9 25 5 48 1 25 6 38 13 14 47 2 33 38 42 37 30 35 24 44 22 28 39 6 9 13 47 34 34 19 24 11 10 29 14 6 40 42 18 33 12 18 9 3
51 57
36 31 7 48 37 19 8 35 30 15 41 5 16 27 17 14 42 38 9 42 48 44 4 5 46 1 24 41 1 14 38 35 14 29 36 8 8 21 19 7 25 44 43 1 32 24 7 11 ...

output:

Case #1:
51 2 1 
1 3 50 4 49 5 48 6 47 7 
7 46 8 45 9 44 10 43 11 42 12 41 13 40 14 
14 39 15 38 16 37 17 36 18 35 19 34 20 33 21 32 22 31 
31 23 30 24 29 25 28 26 27 51 3 2 4 1 5 50 6 49 7 48 8 47 9 46 10 45 11 44 12 43 13 42 
42 14 41 15 40 16 39 17 38 18 37 19 36 20 35 21 34 22 33 23 32 24 
24 31...

result:

ok OK, 780 cases

Test #15:

score: 0
Accepted
time: 70ms
memory: 3592kb

input:

198
101 103
54 54 28 16 56 42 72 79 61 77 67 38 33 96 82 79 2 58 88 43 14 61 70 55 14 58 60 62 63 52 82 79 43 47 49 3 28 80 57 88 55 89 57 50 95 84 58 40 49 13 7 78 11 12 48 21 54 93 9 97 61 66 29 81 97 8 38 3 85 67 84 27 85 76 42 37 28 23 48 25 29 3 71 31 17 41 36 79 26 54 12 92 94 54 53 35 37 19 3...

output:

Case #1:
101 2 1 3 100 4 99 5 98 6 97 7 96 8 95 9 94 10 93 11 92 12 91 13 90 14 89 15 88 16 87 17 86 18 85 19 84 20 83 21 82 22 81 23 80 24 79 25 78 26 77 27 76 28 75 
75 29 74 30 73 31 72 32 71 33 70 34 69 35 68 36 67 37 66 38 65 39 64 40 63 41 62 42 61 43 60 44 59 45 58 46 57 47 56 48 55 49 54 50 ...

result:

ok OK, 198 cases

Test #16:

score: 0
Accepted
time: 83ms
memory: 5380kb

input:

8
499 525
114 220 79 338 377 103 342 3 46 404 13 272 375 131 31 325 354 168 294 378 363 68 104 463 346 360 435 461 276 151 431 405 303 436 349 398 323 172 404 87 194 111 162 179 399 312 13 393 82 149 67 135 88 472 381 9 388 238 448 163 422 113 143 19 311 461 11 263 158 337 479 450 135 47 492 64 8 26...

output:

Case #1:
499 2 1 3 498 4 497 5 496 6 495 7 494 8 493 9 492 10 491 11 490 12 489 13 488 14 487 15 486 16 485 17 484 18 483 19 482 20 481 21 480 22 479 23 478 24 477 25 476 26 475 27 474 28 473 29 472 30 471 31 470 32 469 33 468 34 467 35 466 36 465 37 464 38 463 39 462 40 461 41 460 42 459 43 458 44 ...

result:

ok OK, 8 cases

Test #17:

score: 0
Accepted
time: 95ms
memory: 11204kb

input:

2
999 1031
352 582 8 942 106 301 80 868 705 200 986 193 843 715 563 861 800 694 453 106 243 840 714 919 557 180 732 707 801 523 441 189 227 564 67 874 137 219 509 52 205 480 515 81 295 438 274 911 501 260 992 58 616 536 234 772 738 594 265 697 696 789 156 313 455 755 317 845 18 712 781 95 400 62 457...

output:

Case #1:
999 2 1 3 998 4 997 5 996 6 995 7 994 8 993 9 992 10 991 11 990 12 989 13 988 14 987 15 986 16 985 17 984 18 983 19 982 20 981 21 980 22 979 23 978 24 977 25 976 26 975 27 974 28 973 29 972 30 971 31 970 32 969 33 968 34 967 35 966 36 965 37 964 38 963 39 962 40 961 41 960 42 959 43 958 44 ...

result:

ok OK, 2 cases

Test #18:

score: 0
Accepted
time: 60ms
memory: 11376kb

input:

2
999 999
848 520 572 830 859 562 369 726 766 93 841 929 890 261 644 121 168 989 93 244 595 845 955 371 926 347 296 944 833 471 904 341 13 752 44 712 578 355 833 546 597 407 186 472 785 93 659 892 925 560 562 150 162 186 260 826 366 478 459 430 115 741 834 981 139 109 418 321 149 754 167 207 562 495...

output:

Case #1:
999 2 1 3 998 4 997 5 996 6 995 7 994 8 993 9 992 10 991 11 990 12 989 13 988 14 987 15 986 16 985 17 984 18 983 19 982 20 981 21 980 22 979 23 978 24 977 25 976 26 975 27 974 28 973 29 972 30 971 31 970 32 969 33 968 34 967 35 966 36 965 37 964 38 963 39 962 40 961 41 960 42 959 43 958 44 ...

result:

ok OK, 2 cases

Test #19:

score: 0
Accepted
time: 79ms
memory: 11252kb

input:

2
999 994
452 635 984 227 498 587 35 67 265 269 982 486 255 964 366 159 995 500 427 870 470 559 230 881 359 968 772 169 337 251 547 550 627 7 255 158 919 638 303 132 397 330 406 944 494 748 528 29 323 254 102 22 8 345 762 434 700 48 687 536 740 88 478 746 576 854 917 384 958 338 643 351 314 393 515 ...

output:

Case #1:
999 2 1 3 998 4 997 5 996 6 995 7 994 8 993 9 992 10 991 11 990 12 989 13 988 14 987 15 986 16 985 17 984 18 983 19 982 20 981 21 980 22 979 23 978 24 977 25 976 26 975 27 974 28 973 29 972 30 971 31 970 32 969 33 968 34 967 35 966 36 965 37 964 38 963 39 962 40 961 41 960 42 959 43 958 44 ...

result:

ok OK, 2 cases

Test #20:

score: 0
Accepted
time: 54ms
memory: 3708kb

input:

20000
9 11
3 2 2 5 1 5 4 4 3 4 3
5 6
1 2 2 2 1 2
9 12
6 1 1 2 1 6 6 3 5 2 1 2
9 12
5 2 6 4 1 1 6 1 2 1 5 2
7 10
2 1 2 3 1 4 2 4 1 1
7 9
3 2 2 3 1 2 1 4 3
5 8
1 2 2 1 1 1 1 1
7 8
2 2 3 4 3 4 2 1
5 7
2 1 1 1 2 2 1
7 9
2 2 3 4 3 2 2 2 1
5 6
2 2 1 2 2 1
5 6
2 1 1 2 2 2
5 7
2 1 1 2 2 1 1
9 11
5 6 3 5 2 2...

output:

Case #1:
9 2 1 3 
3 8 4 
4 7 5 
5 6 9 3 2 4 
4 1 
1 5 8 6 7 9 
9 4 3 5 2 
2 6 1 7 8 
8 9 5 4 
4 6 3 7 2 
2 8 1 9 
Case #2:
5 2 
2 1 3 
3 4 5 
5 3 2 
2 4 
4 1 5 
Case #3:
9 2 1 3 8 4 7 
7 5 
5 6 
6 9 3 
3 2 
2 4 1 5 8 6 7 
7 9 4 3 5 2 6 
6 1 7 8 
8 9 5 4 6 3 
3 7 2 
2 8 
8 1 9 
Case #4:
9 2 1 3 8 4 
...

result:

ok OK, 20000 cases

Test #21:

score: 0
Accepted
time: 41ms
memory: 3480kb

input:

5000
13 12
5 8 9 7 5 4 10 10 7 9 2 2
7 13
2 2 1 2 2 2 3 1 1 1 2 1 1
11 16
1 1 5 4 6 2 5 1 5 8 1 1 7 3 4 1
13 17
4 1 9 1 8 1 7 6 4 8 2 8 5 8 4 1 1
5 6
1 2 1 2 2 2
9 9
5 4 5 4 5 1 6 1 5
17 23
4 9 1 10 5 8 8 7 4 11 2 4 6 3 6 7 11 3 10 7 4 5 1
13 14
10 9 1 1 1 10 3 8 8 10 3 3 10 1
7 8
4 1 4 1 4 3 2 2
19...

output:

Case #1:
13 2 1 3 12 4 
4 11 5 10 6 9 7 8 13 
13 3 2 4 1 5 12 6 11 7 
7 10 8 9 13 4 3 5 
5 2 6 1 7 12 
12 8 11 9 10 
10 13 5 4 6 3 7 2 8 1 9 
9 12 10 11 13 6 5 7 4 8 3 
3 9 2 10 1 11 12 13 
13 7 6 8 5 9 4 10 3 11 
11 2 12 
12 1 13 
Case #2:
7 2 1 
1 3 6 
6 4 
4 5 7 
7 3 2 
2 4 1 
1 5 6 7 
7 4 
4 3 
...

result:

ok OK, 5000 cases

Test #22:

score: 0
Accepted
time: 25ms
memory: 3712kb

input:

2000
27 44
5 15 4 6 7 14 9 2 1 24 9 4 12 6 13 23 7 3 21 2 5 2 3 20 8 12 10 21 3 1 6 8 8 4 5 3 19 1 10 7 4 1 1 2
29 31
25 8 18 22 7 7 25 9 26 25 6 11 20 1 7 9 11 14 23 20 1 13 16 1 22 23 14 6 13 1 2
27 27
16 24 6 12 3 3 22 2 24 12 6 10 18 14 8 21 20 14 15 4 23 20 2 14 11 23 4
29 39
15 19 3 7 1 13 20 ...

output:

Case #1:
27 2 1 3 26 4 
4 25 5 24 6 23 7 22 8 21 9 20 10 19 11 18 
18 12 17 13 16 
16 14 15 27 3 2 4 
4 1 5 26 6 25 7 24 
24 8 23 9 22 10 21 11 20 12 19 13 18 14 17 
17 15 16 27 4 3 5 2 6 1 
1 7 26 
26 8 
8 25 9 24 10 23 11 22 12 21 13 20 14 19 15 18 16 17 27 5 4 6 3 7 2 
2 8 1 9 26 10 25 11 24 12 
...

result:

ok OK, 2000 cases

Test #23:

score: 0
Accepted
time: 34ms
memory: 3560kb

input:

800
9 11
5 5 4 1 1 5 5 6 2 1 1
11 14
5 7 5 1 3 3 6 8 3 7 2 3 1 1
19 22
14 10 8 2 9 12 13 2 6 5 8 5 5 1 12 1 10 13 10 2 14 9
9 9
6 5 3 4 3 4 4 6 1
5 7
2 1 1 2 1 2 1
5 7
1 2 2 2 1 1 1
31 29
20 8 18 13 1 24 12 9 12 19 24 25 21 23 6 27 12 10 17 19 23 26 23 5 28 14 11 2 13
49 48
42 46 45 12 5 24 16 28 40...

output:

Case #1:
9 2 1 3 8 4 
4 7 5 6 9 3 
3 2 4 1 5 
5 8 
8 6 
6 7 9 4 3 5 
5 2 6 1 7 8 
8 9 5 4 6 3 7 
7 2 8 
8 1 
1 9 
Case #2:
11 2 1 3 10 4 
4 9 5 8 6 7 11 3 
3 2 4 1 5 10 
10 6 
6 9 7 8 
8 11 4 3 
3 5 2 6 1 7 10 
10 8 9 11 5 4 6 3 7 
7 2 8 1 
1 9 10 11 6 5 7 4 
4 8 3 
3 9 2 10 
10 1 
1 11 
Case #3:
19...

result:

ok OK, 800 cases

Test #24:

score: 0
Accepted
time: 33ms
memory: 3808kb

input:

200
23 26
6 17 15 16 8 5 3 20 8 17 16 8 10 10 10 10 14 1 16 12 7 6 2 4 10 2
47 45
40 15 13 24 37 4 37 8 27 44 12 11 38 19 41 26 22 33 13 26 20 40 39 37 21 16 32 14 9 8 32 36 43 28 29 4 26 38 23 34 5 23 17 16 1
11 12
4 6 7 7 8 4 8 3 1 2 3 2
89 89
57 9 68 20 45 8 78 59 16 83 72 8 42 39 76 76 28 72 46 ...

output:

Case #1:
23 2 1 3 22 4 21 
21 5 20 6 19 7 18 8 17 9 16 10 15 11 14 12 13 23 
23 3 2 4 1 5 22 6 21 7 20 8 19 9 18 10 
10 17 11 16 12 15 13 14 23 4 3 5 2 6 1 7 22 
22 8 21 9 20 10 19 11 18 
18 12 17 13 16 14 
14 15 23 5 
5 4 6 3 7 2 8 1 9 22 10 21 11 20 12 19 13 18 14 17 15 
15 16 23 6 5 7 4 8 3 
3 9 ...

result:

ok OK, 200 cases

Test #25:

score: 0
Accepted
time: 28ms
memory: 4784kb

input:

8
123 123
11 68 57 31 101 57 58 24 104 69 103 1 3 32 74 103 13 86 90 112 64 109 25 68 60 102 89 50 112 37 53 93 24 115 93 21 56 82 80 13 71 54 94 16 6 57 20 39 54 76 48 57 75 35 63 11 86 102 32 20 65 15 81 15 98 14 102 57 92 94 46 104 56 60 57 120 31 114 23 111 15 96 68 93 50 26 114 79 103 59 106 60...

output:

Case #1:
123 2 1 3 122 4 121 5 120 6 119 7 
7 118 8 117 9 116 10 115 11 114 12 113 13 112 14 111 15 110 16 109 17 108 18 107 19 106 20 105 21 104 22 103 23 102 24 101 25 100 26 99 27 98 28 97 29 96 30 95 31 94 32 93 33 92 34 91 35 90 36 89 37 88 38 87 39 86 40 85 41 
41 84 42 83 43 82 44 81 45 80 46...

result:

ok OK, 8 cases

Test #26:

score: 0
Accepted
time: 67ms
memory: 9928kb

input:

2
931 941
37 625 158 286 652 892 205 242 367 627 914 33 501 700 280 117 693 593 389 547 807 758 160 565 24 601 784 551 322 749 463 504 681 221 8 857 511 554 45 797 828 538 779 876 868 475 607 43 161 692 514 687 717 420 610 570 389 112 587 551 890 101 128 371 621 186 263 926 332 130 21 898 311 436 32...

output:

Case #1:
931 2 1 3 930 4 929 5 928 6 927 7 926 8 925 9 924 10 923 11 922 12 921 13 920 14 919 15 918 16 917 17 916 18 915 19 914 20 
20 913 21 912 22 911 23 910 24 909 25 908 26 907 27 906 28 905 29 904 30 903 31 902 32 901 33 900 34 899 35 898 36 897 37 896 38 895 39 894 40 893 41 892 42 891 43 890...

result:

ok OK, 2 cases

Test #27:

score: 0
Accepted
time: 19ms
memory: 5328kb

input:

2
57 60
24 19 36 48 4 43 19 52 8 52 6 17 10 19 18 41 20 36 4 41 38 34 24 26 29 48 15 37 10 7 4 8 16 43 8 9 27 38 12 19 52 31 9 54 49 15 51 24 43 54 29 46 12 40 17 36 50 12 2 1
643 646
230 5 469 246 610 243 221 411 352 98 56 243 481 622 240 492 349 336 548 102 516 326 468 563 272 363 99 156 468 562 5...

output:

Case #1:
57 2 1 3 56 4 55 5 54 6 53 7 52 8 51 9 50 10 49 11 48 12 47 13 46 
46 14 45 15 44 16 43 17 42 18 41 19 40 20 39 21 38 22 37 23 
23 36 24 35 25 34 26 33 27 32 28 31 29 30 57 3 2 4 1 5 56 6 55 7 54 8 53 9 52 10 51 11 50 12 49 13 48 
48 14 47 15 46 16 45 17 44 18 43 19 42 20 41 21 40 22 39 23 ...

result:

ok OK, 2 cases

Test #28:

score: 0
Accepted
time: 45ms
memory: 8136kb

input:

2
939 935
96 887 857 430 351 403 292 594 392 287 841 710 428 591 389 218 248 134 924 445 162 52 491 820 314 711 207 112 874 201 908 448 799 207 6 690 782 141 749 623 628 466 495 700 861 588 791 93 364 36 834 772 774 619 615 46 358 5 493 382 121 891 71 564 219 201 496 495 883 781 546 394 548 936 643 ...

output:

Case #1:
939 2 1 3 938 4 937 5 936 6 935 7 934 8 933 9 932 10 931 11 930 12 929 13 928 14 927 15 926 16 925 17 924 18 923 19 922 20 921 21 920 22 919 23 918 24 917 25 916 26 915 27 914 28 913 29 912 30 911 31 910 32 909 33 908 34 907 35 906 36 905 37 904 38 903 39 902 40 901 41 900 42 899 43 898 44 ...

result:

ok OK, 2 cases

Test #29:

score: 0
Accepted
time: 43ms
memory: 11084kb

input:

2
763 776
379 463 566 538 49 15 664 613 227 59 631 331 374 87 4 325 559 80 459 107 528 340 427 420 99 171 492 465 572 316 723 598 423 135 14 156 604 99 648 509 657 449 715 50 157 652 701 521 644 529 420 385 173 55 758 649 311 135 744 47 370 488 40 405 722 284 443 676 57 552 283 241 26 449 522 201 10...

output:

Case #1:
763 2 1 3 762 4 761 5 760 6 759 7 758 8 757 9 756 10 755 11 754 12 753 13 752 14 751 15 750 16 749 17 748 18 747 19 746 20 745 21 744 22 743 23 742 24 741 25 740 26 739 27 738 28 737 29 736 30 735 31 734 32 733 33 732 34 731 35 730 36 729 37 728 38 727 39 726 40 725 41 724 42 723 43 722 44 ...

result:

ok OK, 2 cases

Test #30:

score: 0
Accepted
time: 71ms
memory: 11196kb

input:

2
999 504
991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 991 99...

output:

Case #1:
999 2 1 3 998 4 997 5 996 6 995 7 994 8 993 9 992 10 991 11 990 12 989 13 988 14 987 15 986 16 985 17 984 18 983 19 982 20 981 21 980 22 979 23 978 24 977 25 976 26 975 27 974 28 973 29 972 30 971 31 970 32 969 33 968 34 967 35 966 36 965 37 964 38 963 39 962 40 961 41 960 42 959 43 958 44 ...

result:

ok OK, 2 cases

Test #31:

score: 0
Accepted
time: 62ms
memory: 11248kb

input:

2
999 501
996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 996 99...

output:

Case #1:
999 2 1 3 998 4 997 5 996 6 995 7 994 8 993 9 992 10 991 11 990 12 989 13 988 14 987 15 986 16 985 17 984 18 983 19 982 20 981 21 980 22 979 23 978 24 977 25 976 26 975 27 974 28 973 29 972 30 971 31 970 32 969 33 968 34 967 35 966 36 965 37 964 38 963 39 962 40 961 41 960 42 959 43 958 44 ...

result:

ok OK, 2 cases

Test #32:

score: 0
Accepted
time: 47ms
memory: 3548kb

input:

20000
9 11
3 2 2 5 1 5 4 4 3 4 3
5 6
1 2 2 2 1 2
9 12
6 1 1 2 1 6 6 3 5 2 1 2
9 12
5 2 6 4 1 1 6 1 2 1 5 2
7 10
2 1 2 3 1 4 2 4 1 1
7 9
3 2 2 3 1 2 1 4 3
5 8
1 2 2 1 1 1 1 1
7 8
2 2 3 4 3 4 2 1
5 7
2 1 1 1 2 2 1
7 9
2 2 3 4 3 2 2 2 1
5 6
2 2 1 2 2 1
5 6
2 1 1 2 2 2
5 7
2 1 1 2 2 1 1
9 11
5 6 3 5 2 2...

output:

Case #1:
9 2 1 3 
3 8 4 
4 7 5 
5 6 9 3 2 4 
4 1 
1 5 8 6 7 9 
9 4 3 5 2 
2 6 1 7 8 
8 9 5 4 
4 6 3 7 2 
2 8 1 9 
Case #2:
5 2 
2 1 3 
3 4 5 
5 3 2 
2 4 
4 1 5 
Case #3:
9 2 1 3 8 4 7 
7 5 
5 6 
6 9 3 
3 2 
2 4 1 5 8 6 7 
7 9 4 3 5 2 6 
6 1 7 8 
8 9 5 4 6 3 
3 7 2 
2 8 
8 1 9 
Case #4:
9 2 1 3 8 4 
...

result:

ok OK, 20000 cases

Test #33:

score: 0
Accepted
time: 312ms
memory: 11276kb

input:

18968
51 55
2 9 14 17 31 21 36 21 16 40 32 9 25 5 48 1 25 6 38 13 14 47 2 33 38 42 37 30 35 24 44 22 28 39 6 9 13 47 34 34 19 24 11 10 29 14 6 40 42 18 33 12 18 9 3
51 57
36 31 7 48 37 19 8 35 30 15 41 5 16 27 17 14 42 38 9 42 48 44 4 5 46 1 24 41 1 14 38 35 14 29 36 8 8 21 19 7 25 44 43 1 32 24 7 1...

output:

Case #1:
51 2 1 
1 3 50 4 49 5 48 6 47 7 
7 46 8 45 9 44 10 43 11 42 12 41 13 40 14 
14 39 15 38 16 37 17 36 18 35 19 34 20 33 21 32 22 31 
31 23 30 24 29 25 28 26 27 51 3 2 4 1 5 50 6 49 7 48 8 47 9 46 10 45 11 44 12 43 13 42 
42 14 41 15 40 16 39 17 38 18 37 19 36 20 35 21 34 22 33 23 32 24 
24 31...

result:

ok OK, 18968 cases