Codeforces Round 694 (Div. 1)


A. Strange Birthday Party
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5 4
2 3 4 3 2
3 5 12 20
5 5
5 4 3 2 1
10 40 90 160 250
Output
30
190
Input
1
1 1
1
1
Output
1
----------------------------------------------------------------------------------------------------
B. Strange Definition
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4
6 8 4 2
1
0
6
12 3 20 5 80 1
1
1
Output
2
3
----------------------------------------------------------------------------------------------------
C. Strange Shuffle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
2
1
2
3
2
Output
? 1
? 1
? 2
? 3
? 4
! 2
----------------------------------------------------------------------------------------------------
D. Strange Housing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3 2
3 2
2 1
4 2
1 4
2 3
Output
YES
2
1 3 
NO
Input
1
17 27
1 8
2 9
3 10
4 11
5 12
6 13
7 14
8 9
8 14
8 15
9 10
9 15
10 11
10 15
10 17
11 12
11 17
12 13
12 16
12 17
13 14
13 16
14 16
14 15
15 16
15 17
16 17
Output
YES
8
1 3 4 5 6 9 14 17 
----------------------------------------------------------------------------------------------------
E. Strange Permutation
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3 1 9
1 2 3
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
6 4 4
6 5 4 3 1 2
1 1
3 14
1 59
2 6
Output
1
2
3
1
3
2
2
1
3
1
4
-1
5
Input
1
12 4 2
1 2 3 4 5 6 7 8 9 10 11 12
2 20
2 21
Output
2
2
----------------------------------------------------------------------------------------------------
F. Strange Covering
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
9 1
1 6
2
8 10
0 7
4
0 0
1 1
9 9
10 10
Output
0
0
2
----------------------------------------------------------------------------------------------------
