问题 C: 凯法和菜肴

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:16 通过:10

题目描述


当Kefa来到餐厅,坐在一张桌子旁时,服务员立即将菜单端给他。有n道菜。凯法知道他需要的正是米菜。但那时,他不想点两次同样的菜来品尝尽可能多的菜肴。
可法知道,第一道菜给了他一个满足感。但是有些菜搭配得不好,有些菜搭配得很好。Kefa 给自己设定了吃以下类型食物的 k 条规则——如果他正好在菜 y 之前菜 x(x 和 y 之间不应该有其他菜),那么他的满意度就会提高 c
当然,我们的鹦鹉想从去餐厅中获得最大的满足感。帮助他完成这项艰巨的任务!
输入
输入的第一行包含三个空格分隔的数字,nmk1≤mn≤180≤kn*(n-1)-菜单上的菜肴数量,Kefa需要吃饱的份量以及饮食规则的数量。
第二行包含 n 个空格分隔的数字 a i, (0≤a i≤109) - 他从第 i 道菜中获得的满足感。
接下来的 k 行包含规则。第 i 条规则由三个数字 x i、y i 和 c i (1≤x i,y i≤n, 0≤ci≤109) 描述。这意味着,如果你在菜 y i 之前吃菜 x i,那么 Kefa 的满意度会增加 c i。保证没有这样的索引对 i 和 j (1≤i<j≤k),即 x i=x j 和 yi=yj
输出
在输出的单行打印中,Kefa 可以从去餐厅中获得的最大满足感。






When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible.
Kefa knows that the i-th dish gives him ai units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself k rules of eating food of the following type − if he eats dish x exactly before dish y (there should be no other dishes between x and y), then his satisfaction level raises by c.
Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task!

Input
The first line of the input contains three space-separated numbers, n, m and k (1≤mn≤18, 0≤kn*(n-1)) − the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules.
The second line contains n space-separated numbers ai, (0≤ai≤109) − the satisfaction he gets from the i-th dish.
Next k lines contain the rules. The i-th rule is described by the three numbers xi, yi and ci (1≤xi,yin, 0≤ci≤109). That means that if you eat dish xi right before dish yi, then the Kefa's satisfaction increases by ci. It is guaranteed that there are no such pairs of indexes i and j (1≤i<jk), that xi=xj and yi=yj.

Output
In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant.
Examples
Input
2 2 1
1 1
2 1 1
Output
3
Input
4 3 2
1 2 3 4
2 1 5
3 4 2
Output
12
Note
In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule.
In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.

输入样例 复制


输出样例 复制