Good Bye 2014


A. New Year Transportation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 4
1 2 1 2 1 2 1
Output
YES
Input
8 5
1 2 1 2 1 1 1
Output
NO
----------------------------------------------------------------------------------------------------
B. New Year Permutation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
5 2 4 3 6 7 1
0001001
0000000
0000010
1000001
0000000
0010000
1001000
Output
1 2 4 3 6 7 5
Input
5
4 2 1 5 3
00100
00011
10010
01101
01010
Output
1 2 3 4 5
----------------------------------------------------------------------------------------------------
C. New Year Book Reading
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
1 2 3
1 3 2 3 1
Output
12
----------------------------------------------------------------------------------------------------
D. New Year Santa Network
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 5
1 3 3
5
1 4
2 2
1 2
2 1
1 1
Output
14.0000000000
12.0000000000
8.0000000000
6.0000000000
4.0000000000
Input
6
1 5 3
5 3 2
6 1 7
1 4 4
5 2 3
5
1 2
2 1
3 5
4 1
5 2
Output
19.6000000000
18.6000000000
16.6000000000
13.6000000000
12.6000000000
----------------------------------------------------------------------------------------------------
E. New Year Domino
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 5
3 3
4 4
9 2
10 1
12 1
4
1 2
2 4
2 5
2 6
Output
0
1
1
2
----------------------------------------------------------------------------------------------------
F. New Year Shopping
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
2 3 2
3 5 1
4 7 2
11 15 5
4
1 3
2 5
2 6
5 14
Output
5
8
10
18
Input
5 4
3 2 1
7 4 4
2 1 2
6 3 5
3 2 2
10
1 5
2 5
4 8
4 9
4 10
5 8
5 9
5 10
8 4
7 9
Output
2
3
5
5
6
4
5
6
0
4
----------------------------------------------------------------------------------------------------
G. New Year Running
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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