J. Ski Trip
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output
Example
Input
6 5
1 2 1 4 4
3 1 1
5 4 3
6 4 10
5 1 5
6 1 6
Output
10