Educational Codeforces Round 97 (Rated for Div. 2)


A. Marketing Scheme
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 4
1 2
120 150
Output
YES
NO
YES
----------------------------------------------------------------------------------------------------
B. Reverse Binary Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
10
4
0110
8
11101000
Output
0
1
2
----------------------------------------------------------------------------------------------------
C. Chef Monocarp
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
6
4 2 4 4 5 2
7
7 7 7 7 7 7 7
1
1
5
5 1 2 4 3
4
1 4 4 4
21
21 8 1 4 1 5 21 1 8 21 11 21 11 3 12 8 19 15 9 11 13
Output
4
12
0
0
2
21
----------------------------------------------------------------------------------------------------
D. Minimal Height Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
1 4 3 2
2
1 2
3
1 2 3
Output
3
1
1
----------------------------------------------------------------------------------------------------
E. Make It Increasing
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 2
1 2 1 1 3 5 1
3 5
Output
4
Input
3 3
1 3 2
1 2 3
Output
-1
Input
5 0
4 3 1 2 3
Output
2
Input
10 3
1 3 5 6 12 9 8 10 13 15
2 4 9
Output
3
----------------------------------------------------------------------------------------------------
F. Emotional Fishermen
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 4 9
Output
20
Input
4
4 3 2 1
Output
0
Input
3
4 2 1
Output
6
Input
8
42 1337 13 37 420 666 616 97
Output
19200
----------------------------------------------------------------------------------------------------
G. Death DBMS
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 8
kurou
takuo
takeshi
naomi
shingo
2 nakiraomi
2 abanaomicaba
1 3 943
2 takuotakeshishingo
1 5 135832
2 shingotakeshi
1 5 0
2 shingotakeshi
Output
-1
0
943
135832
943
Input
6 15
a
ab
ba
b
a
ba
2 aa
1 4 4
2 bbb
1 2 1
1 2 18
2 b
2 c
1 6 10
2 aba
2 abbbba
1 2 12
2 bbaaab
1 1 11
1 5 5
2 baa
Output
0
4
4
-1
18
18
12
11
----------------------------------------------------------------------------------------------------
