Codeforces Round 914 (Div. 2)


A. Forked!
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 1
0 0
3 3
1 1
3 1
1 3
4 4
0 0
8 0
4 2
1 4
3 4
Output
2
1
2
0
----------------------------------------------------------------------------------------------------
B. Collecting Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5
20 5 1 4 2
3
1434 7 1442
1
1
5
999999999 999999999 999999999 1000000000 1000000000
Output
4 3 0 3 1 
1 0 2 
0 
4 4 4 4 4 
----------------------------------------------------------------------------------------------------
C. Array Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 2
3 9 7 15 1
4 3
7 4 15 12
6 2
42 47 50 54 62 79
2 1
500000000000000000 1000000000000000000
Output
1
0
3
500000000000000000
----------------------------------------------------------------------------------------------------
D1. Set To Max (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
1 2 3 2 4
1 3 3 2 4
5
3 4 2 2 4
3 4 3 4 4
5
3 2 1 1 1
3 3 3 2 2
2
1 1
1 2
3
1 1 2
2 1 2
Output
YES
NO
YES
NO
NO
----------------------------------------------------------------------------------------------------
D2. Set To Max (Hard Version)
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
1 2 3 2 4
1 3 3 2 4
5
3 4 2 2 4
3 4 3 4 4
5
3 2 1 1 1
3 3 3 2 2
2
1 1
1 2
3
1 1 2
2 1 2
Output
YES
NO
YES
NO
NO
----------------------------------------------------------------------------------------------------
E. Tree Queries
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7 7
1 2
1 3
3 4
2 5
2 6
6 7
2 0
2 1 1
2 2 1 6
3 1 4
3 1 1
5 0
5 2 1 6
Output
3
2
1
4
1
4
1
Input
4 4
1 2
1 3
2 4
2 1 3
3 1 4
2 1 4
2 3 1 3 4
Output
1
2
2
0
----------------------------------------------------------------------------------------------------
F. Beautiful Tree
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7 5
1 2
1 3
1 4
3 5
4 6
3 7
1 6 5 1
2 6 7 3
1 2 7 1
1 7 5 7
2 4 2 2
Output
1 6 7 5 3 4 2 
Input
2 2
1 2
1 1 2 1
1 1 2 2
Output
-1
----------------------------------------------------------------------------------------------------
