cf/mirror

Optimal Subsequences (Hard Version)

CF
1227D21800· expert3s256 MB⌨ stdin/stdout

Examples

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