Kotlin Heroes: Episode 7


A. Travel to Bertown
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 3
1 4
2 6
4 10
2 4
2 3
5 8
2 4
4 4
1 3
Output
4
0
1
----------------------------------------------------------------------------------------------------
B. Nearest Point Function
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
2
1 3
2
1 100
3
1 50 101
2
1 1000000000
2
1 999999999
6
1 2 5 7 9 11
6
1 2 5 8 9 12
Output
YES
NO
NO
NO
YES
YES
NO
----------------------------------------------------------------------------------------------------
C. Sweets
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
6 4
000111
7 3
0000100
3 2
000
5 1
10011
Output
4
4
0
5
----------------------------------------------------------------------------------------------------
D. String Searching
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
a
c
4
aa
ca
mm
cf
Output
1
2
0
1
Input
6 3
dba
abd
cbb
ada
add
bdd
5
ccbb
abdd
adba
bada
dddd
Output
1
3
2
1
0
----------------------------------------------------------------------------------------------------
E. Chess Team Forming
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
10 3 4 6 1
9 4 2 5 9 8
5
1 7 6 4 8
Output
4 2 3 4 2
Input
3
5 1 8
8 2 10 1
10
1 2 3 4 5 6 7 8 9 10
Output
3 3 3 3 3 2 2 2 1 0
Input
1
10
10 5
2
5 15
Output
0 -5
----------------------------------------------------------------------------------------------------
F. Binary String Partition
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
00100010
Output
2 1 1 1 1 1 1 1
Input
1001011100
Output
3 2 2 2 1 1 1 1 1 1
----------------------------------------------------------------------------------------------------
G. Biome Map
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 3
0 2 5
0 1 0
3 5
0 3 4 9 11
1 5 0 10 12
0 6 7 0 0
2 2
2 0
0 5
1 2
13 37
Output
1 3
5 2 1 
2 8
11 9 4 3 5 1 5 6 
12 10 9 4 3 5 6 7 
-1
1 2
13 37 
----------------------------------------------------------------------------------------------------
H. Submatrices
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
ABB
ABA
Output
9 9 0 0 0 
Input
6 6
EDCECE
EDDCEB
ACCECC
BAEEDC
DDDDEC
DDAEAD
Output
56 94 131 103 57 
Input
3 10
AEAAEEEEEC
CEEAAEEEEE
CEEEEAACAA
Output
78 153 99 0 0 
----------------------------------------------------------------------------------------------------
I. Excursions
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 1 2
10 20
1 1
2 1
Output
10
Input
3 3 6
10 20 30
1 3
3 1
2 3
2 1
3 2
1 2
Output
0
----------------------------------------------------------------------------------------------------
J. Pawns
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1
5 1
2 2
Output
1
Input
3
3 2
1 3
1 1
Output
2
Input
2
1 1
2 2
Output
1
----------------------------------------------------------------------------------------------------
