cf/mirror

Christmas Reindeer (hard version)

CF
2182F22500· grandmaster4s512 MB⌨ stdin/stdout

Examples

Sample 1of 3
Input
3 7
2 1 1
3 5
3 6
1 2
3 6
3 5
2 1
3 5
Output
3
0
4
10
4
Sample 2of 3
Input
5 5
6 9 2 3 5
3 518
1 4
2 9
1 10
3 1016
Output
12
32
Sample 3of 3
Input
5 20
56 58 31 56 57
3 584133699915613698
1 26
3 718934517698133644
1 43
3 853795525565803934
3 371128907885602007
1 54
1 25
3 12283451778216771
2 25
3 269837405423769340
1 0
3 81332884431075468
1 23
3 4256984962444022
3 668408003982766102
3 923410222653374550
3 340313743235311415
3 550166282440775769
3 445344499963496530
Output
0
0
0
24
496
128
416
992
0
0
320
0
0
2182F2.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)