cf/mirror

Optimal Encoding

CF
1508F3500· legendary gm7s1024 MB⌨ stdin/stdout

Examples

Sample 1of 3
Input
4 3
2 4 1 3
1 3
2 4
1 4
Output
2
4
3
Sample 2of 3
Input
8 4
3 7 4 8 1 5 2 6
3 6
1 6
3 8
1 8
Output
3
5
9
7
Sample 3of 3
Input
10 10
10 5 1 2 7 3 9 4 6 8
2 2
4 5
6 8
4 10
4 4
2 7
2 2
7 8
3 7
2 10
Output
0
1
3
6
6
9
9
9
9
8
1508F.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)