This is my code:
https://www.codechef.com/viewsolution/35570844
Input:
10 11
7 18 16 14 16 7 13 10 2 3
8 11 20 4 7 1 7 13 17 12
2 8 10
2 1 3
1 8 6
1 3 3
2 10 8
1 7 2
2 10 4
1 10 5
1 9 5
1 1 4
2 2 1
Your output:
25
-1
-1
-1
19
Expected Output:
25
-1
-1
-1
15