Codeforces Round 912 (Div. 2)


A. Halloumi Boxes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 2
1 2 3
3 1
9 9 9
4 4
6 4 2 1
4 3
10 3 830 14
2 1
3 1
Output
YES
YES
YES
YES
NO
----------------------------------------------------------------------------------------------------
B. StORage room
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
0
4
0 3 3 5
3 0 3 7
3 3 0 7
5 7 7 0
5
0 7 7 5 5
7 0 3 2 6
7 3 0 3 7
5 2 3 0 4
5 6 7 4 0
3
0 0 1
0 0 0
1 0 0
Output
YES
7
YES
1 3 2 5 
YES
5 2 3 0 4
NO
----------------------------------------------------------------------------------------------------
C. Theofanis' Nightmare
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
6
1 -3 7 -6 2 5
4
2 9 -5 -3
8
-3 -4 2 -5 1 10 17 23
1
830
Output
32
4
343
830
----------------------------------------------------------------------------------------------------
D1. Maximum And Queries (easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 3 7 5
2
10
Output
2
6
Input
3 5
4 0 2
9
8
17
1
3
Output
5
4
7
0
1
Input
1 2
10
5
2318381298321
Output
15
2318381298331
----------------------------------------------------------------------------------------------------
D2. Maximum And Queries (hard version)
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 3 7 5
2
10
Output
2
6
Input
3 5
4 0 2
9
8
17
1
3
Output
5
4
7
0
1
Input
1 2
10
5
2318381298321
Output
15
2318381298331
----------------------------------------------------------------------------------------------------
E. Geo Game
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
6
4 6
7 6
8 5
2 1
6 2
6 4
3 3
2
5
1
4
1 1
3 2
2 1
3 3
1 2
2
3
Output
Second
4
6
3
First
1
4
----------------------------------------------------------------------------------------------------
F. Babysitting
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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