Codeforces Global Round 13


A. K-th Largest Value
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 1 0 1 0
2 3
1 2
2 3
2 1
2 5
Output
1
0
1
0
----------------------------------------------------------------------------------------------------
B. Minimal Cost
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 4
2 2
2 3 4
3 2
2 4 3
3 2
Output
7
3
3
----------------------------------------------------------------------------------------------------
C. Pekora and Trampoline
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
7
1 4 2 2 2 2 2
2
2 3
5
1 1 1 1 1
Output
4
3
0
----------------------------------------------------------------------------------------------------
D. Zookeeper and The Infinite Zoo
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 4
3 6
1 6
6 2
5 5
Output
YES
YES
NO
NO
YES
----------------------------------------------------------------------------------------------------
E. Fib-tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2
2 3
Output
YES
Input
5
1 2
1 3
1 4
1 5
Output
NO
Input
5
1 3
1 2
4 5
3 4
Output
YES
----------------------------------------------------------------------------------------------------
F. Magnets
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
4
0
1
0
0
Output
? 1 1
3
4
? 1 2
1
2 3
? 1 1
1
4
? 1 1
1
3
! 2 3 4
----------------------------------------------------------------------------------------------------
G. Switch and Flip
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
----------------------------------------------------------------------------------------------------
H. Yuezheng Ling and Dynamic Tree
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 4
1 2 3 3 4
2 3 4
1 2 3 1
2 5 6
2 2 3
Output
3
3
1
----------------------------------------------------------------------------------------------------
I. Ruler Of The Zoo
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 1 2
10 8 11
9 0 3
7 4 6
Output
-1 -1
Input
5
11 7 12
8 6 14
2 1 10
13 0 9
5 3 4
Output
1 7
----------------------------------------------------------------------------------------------------
