404653: GYM101604 E Mike and Cities

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Mike and Citiestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Mike has a vacation of m days, and he's going to explore n cities numbered from 1 to n. He can start to visit on the first day any city. If on day d he visited city c1 then on the day d + 1 he can visit city c1 (stay where he's for one more day) or city c2 if there is a road between cities c1 and c2.

He can visit a city any number of times. There are k types of roads, each type is described using 3 integers ai,  bi and ci, signifying that there are bidirectional roads between cities (ai and ci),  (ai + 1 and ci) ...  (bi and ci) note that there can be a road between a city and itself, it is also given the fact that ci ≠ cj (1 ≤ i < j ≤ k).

In day i (1 ≤ i ≤ m), if he visits city j (1 ≤ j ≤ n) he gets pleasure Pi, j.

Help him find the maximal sum of pleasure in all the days he can achieve.

Input

The first line contains 3 integers n,  m and k (1 ≤ n × m,  k ≤ 300, 000).

The next m lines contains n integers separated by a space, representing matrix P (0 ≤ Pi, j ≤ 109).

The next k lines, each one contains 3 integers separated by a space, representing the different types of roads – ai,  bi,  ci (1 ≤ ai ≤ bi ≤ n,  1 ≤ ci ≤ n).

Output

Output the maximal sum of pleasures he can achieve.

ExampleInput
3 3 2
1 2 3
5 6 7
11 5 3
1 1 2
2 3 3
Output
20

加入题单

上一题 下一题 算法标签: