题目描述
Given are positive integers N, M, Q, and Q quadruples of integers ( ai , bi , ci , di ).
Consider a sequence A satisfying the following conditions:
- A is a sequence of N positive integers.
- 1≤A1≤A2≤⋯≤AN≤M.
Let us define a score of this sequence as follows:
- The score is the sum of di over all indices i such that Abi−Aai=ci. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
给出正整数 N , M , Q , Q 的四倍整数 ( ai , bi , ci , di )。
考虑满足以下条件的序列 A :
- A 是一个由 N 个正整数组成的序列。
- 1≤A1≤A2≤⋯≤AN≤M .
我们对这个序列的分数定义如下
- 分数是 Abi−Aai=ci 的所有索引 i 中 di 的总和。(如果没有 i ,则得分为 0 )。
求 A 的最大可能得数。
输入格式
输入内容按以下格式标准输入:
N M Q
a1 b1 c1 d1
:
aQ bQ cQ dQ
输出格式
打印最大可能得分 A 。
样例 #1
样例输入 #1
样例输出 #1
样例 #2
样例输入 #2
样例输出 #2
样例 #3
样例输入 #3
样例输出 #3
说明
数据规模与约定
- 所有输入值均为整数。
- 2≤N≤10
- 1≤M≤10
- 1≤Q≤50
- 1≤ai<bi≤N ( i=1,2,...,Q )
- 0≤ci≤M−1 ( i=1,2,...,Q )
- (ai,bi,ci)=(aj,bj,cj) (其中 i=j )
- 1≤di≤105 ( i=1,2,...,Q )
样例 1 解释
当 A={1,3,4} 时,它的得分是 110 。在这些条件下,没有序列的得分大于 110 ,因此答案是 110 。