Codeforces Round 595 (Div. 3)


A. Yet Another Dividing into Teams
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
2 10 1 20
2
3 6
5
2 3 4 99 100
1
42
Output
2
1
2
1
----------------------------------------------------------------------------------------------------
B1. Books Exchange (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5
1 2 3 4 5
3
2 3 1
6
4 6 2 1 5 3
1
1
4
3 4 1 2
5
5 1 2 4 3
Output
1 1 1 1 1 
3 3 3 
2 3 3 2 1 3 
1 
2 2 2 2 
4 4 4 1 4 
----------------------------------------------------------------------------------------------------
B2. Books Exchange (hard version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5
1 2 3 4 5
3
2 3 1
6
4 6 2 1 5 3
1
1
4
3 4 1 2
5
5 1 2 4 3
Output
1 1 1 1 1 
3 3 3 
2 3 3 2 1 3 
1 
2 2 2 2 
4 4 4 1 4 
----------------------------------------------------------------------------------------------------
C1. Good Numbers (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
----------------------------------------------------------------------------------------------------
C2. Good Numbers (hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
1
2
6
13
14
3620
10000
1000000000000000000
Output
1
3
9
13
27
6561
19683
1350851717672992089
----------------------------------------------------------------------------------------------------
D1. Too Many Segments (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
Output
3
1 4 7 
Input
5 1
29 30
30 30
29 29
28 30
30 30
Output
3
1 2 4 
Input
6 1
2 3
3 3
2 3
2 2
2 3
2 3
Output
4
1 3 5 6 
----------------------------------------------------------------------------------------------------
D2. Too Many Segments (hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
Output
3
4 6 7 
Input
5 1
29 30
30 30
29 29
28 30
30 30
Output
3
1 4 5 
Input
6 1
2 3
3 3
2 3
2 2
2 3
2 3
Output
4
1 3 5 6 
----------------------------------------------------------------------------------------------------
E. By Elevator or Stairs?
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 2
7 6 18 6 16 18 1 17 17
6 9 3 10 9 1 10 1 5
Output
0 7 13 18 24 35 36 37 40 45 
Input
10 1
3 2 3 1 3 3 1 4 1
1 2 3 4 4 1 2 1 3
Output
0 2 4 7 8 11 13 14 16 17 
----------------------------------------------------------------------------------------------------
F. Maximum Weight Subset
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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