DP。
const maxn=;
var t,s,n,i,j,m,l,a,c,d:longint;
f,e:array[..,..maxn] of longint;
q:array[..] of longint;
g:array[..maxn] of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
begin
readln(t,s,n);
for i:= to s do
begin
readln(m,l,a);
e[a,l+m]:=max(e[a,l+m],m);
end;
for i:= to do q[i]:=maxn;
for i:= to n do
begin
readln(c,d);
for j:=c to do
q[j]:=d+q[j]-max(d,q[j]);
end;
//for i:=1 to 100 do
//writeln(q[i]);
for i:= to t do
for j:= to do f[j,i]:=-maxn;
f[,]:=; //g[1]:=0;
for i:= to t do
for j:= to do
begin
f[j,i]:=f[j,i-];
if e[j,i]> then f[j,i]:=max(f[j,i],g[e[j,i]]);
if q[j]<=i then f[j,i]:=max(f[j,i],f[j,i-q[j]]+);
g[i]:=max(g[i],f[j,i]);
end;
writeln(g[t]);
end.
(转载请注明出处:http://www.cnblogs.com/Kalenda/)