Codeforces Round 466 (Div. 2)


A. Points on the line
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
2 1 4
Output
1
Input
3 0
7 7 7
Output
0
Input
6 3
1 3 4 6 9 10
Output
3
----------------------------------------------------------------------------------------------------
B. Our Tanya is Crying Out Loud
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
----------------------------------------------------------------------------------------------------
C. Phone Numbers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
abc
Output
aca
Input
3 2
abc
Output
ac
Input
3 3
ayy
Output
yaa
Input
2 3
ba
Output
baa
----------------------------------------------------------------------------------------------------
D. Alena And The Heater
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 4 5
00001
Output
6 15
Input
10
-10 -9 -8 -7 -6 6 7 8 9 10
0000111110
Output
-5 5
----------------------------------------------------------------------------------------------------
E. Cashback
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
Output
6
Input
12 10
1 1 10 10 10 10 10 10 9 10 10 10
Output
92
Input
7 2
2 3 6 4 5 7 1
Output
17
Input
8 4
1 3 4 5 5 3 4 1
Output
23
----------------------------------------------------------------------------------------------------
F. Machine Learning
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
10 4
1 2 3 1 1 2 2 2 9 9
1 1 1
1 2 8
2 7 1
1 2 8
Output
2
3
2
----------------------------------------------------------------------------------------------------
