Codeforces Round 398 (Div. 2)


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

Examples
Input
3
3 1 2
Output
3
 
2 1
Input
5
4 5 1 2 3
Output
 
5 4
 
 
3 2 1
----------------------------------------------------------------------------------------------------
B. The Queue
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 15 2
2
10 13
Output
12
Input
8 17 3
4
3 4 5 8
Output
2
----------------------------------------------------------------------------------------------------
C. Garland
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 4
0 5
4 2
2 1
1 1
4 2
Output
1 4
Input
6
2 4
0 6
4 2
2 1
1 1
4 2
Output
-1
----------------------------------------------------------------------------------------------------
D. Cartons of milk
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 6 2
1 0 1
2 0 2 0 0 2
Output
3
1 2 3
Input
3 1 2
0 0 0
1
Output
-1
Input
2 1 2
0 1
0
Output
1
1 
----------------------------------------------------------------------------------------------------
E. Change-free
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 42
117 71 150 243 200
1 1 1 1 1
Output
79
1 17
1 0
2 0
2 43
2 0
Input
3 0
100 50 50
1 3 2
Output
150
1 0
1 0
0 50
Input
5 42
117 71 150 243 200
5 4 3 2 1
Output
230
1 17
1 0
1 50
3 0
2 0
----------------------------------------------------------------------------------------------------
