Codeforces Round 787 (Div. 3)


A. Food for Animals
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1 1 4 2 3
0 0 0 0 0
5 5 0 4 6
1 1 1 1 1
50000000 50000000 100000000 100000000 100000000
0 0 0 100000000 100000000
1 3 2 2 5
Output
YES
YES
NO
YES
YES
NO
NO
----------------------------------------------------------------------------------------------------
B. Make It Increasing
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
3
3 6 5
4
5 3 2 1
5
1 2 3 4 5
1
1000000000
4
2 8 7 5
5
8 26 5 21 10
2
5 14
Output
2
-1
0
0
4
11
0
----------------------------------------------------------------------------------------------------
C. Detective Task
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
0
1
1110000
?????
1?1??0?0
0?0???
??11
??0??
Output
1
1
2
5
4
1
1
3
----------------------------------------------------------------------------------------------------
D. Vertical Paths
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5
3 1 3 3 1
4
1 1 4 1
7
1 1 2 3 4 5 6
1
1
6
4 4 4 4 1 2
4
2 2 2 2
Output
3
3
3 1 5
1
2
1
4
2
2
1 2
2
4 3
1
7
1 2 3 4 5 6 7
1
1
1
3
3
4 1 5
2
2 6
1
3
3
2
2 1
1
3
1
4
----------------------------------------------------------------------------------------------------
E. Replace With the Previous, Minimize
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 2
cba
4 5
fgde
7 5
gndcafb
4 19
ekyv
Output
aaa
agaa
bnbbabb
aapp
----------------------------------------------------------------------------------------------------
F. Vlad and Unfinished Business
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 1
1 3
2
1 3
1 2
6 4
3 5
1 6 2 1
1 3
3 4
3 5
5 6
5 2
6 2
3 2
5 3
1 3
3 4
3 5
5 6
5 2
Output
3
7
2
----------------------------------------------------------------------------------------------------
G. Sorting Pancakes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 19
5 3 2 3 3 3
Output
2
Input
3 6
3 2 1
Output
0
Input
3 6
2 1 3
Output
1
Input
6 19
3 4 3 3 5 1
Output
3
Input
10 1
0 0 0 0 0 0 0 0 0 1
Output
9
----------------------------------------------------------------------------------------------------
