1003度度熊与邪恶大魔王
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
//typedef _int64 LL; 我是vc6编译(c90标准的) 而long long c99新加的不支持 但在百度之星上的编译器执行会报Compilation Error 所以改成 long long 型和_int64等同
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn=100000+5;
const int maxm=1000+5;
int a[maxn],b[maxn];
int k[maxm],p[maxm];
LL dp[maxn][20];//血量为i,防御为j,消耗的最少晶石
int max(int a,int b){
return a>b?a:b;
}
int min(int a,int b){
return a<b?a:b;
}
int main(){
int n,m;
while(cin>>n>>m){
int mhp = 0; //怪物最大hp
int mf = 0; //怪物最大防御
int mg = 0; //最大攻击
int i,j;
for( i=0;i<n;i++){
scanf("%d%d",&a[i],&b[i]);
mf = max(mf,b[i]);
mhp = max(mhp,a[i]);
}
for( j=0;j<m;j++){
scanf("%d%d",&k[j],&p[j]);
mg = max(mg,p[j]);
}
if(mg<=mf){
printf("-1\n");
continue;
}
memset(dp,INF,sizeof(dp));
for( j=0;j<=10;j++){ //防御值
for( i=1;i<=mhp;i++){ //血量值
for(int z=0;z<m;z++){//第z个技能
if(p[z]<=j) continue;
else if(i<=p[z]-j)
dp[i][j] = min(dp[i][j],k[z]);
else
dp[i][j] = min(dp[i][j],dp[i-(p[z]-j)][j]+k[z]);
}
}
}
LL res = 0;
for( i=0;i<n;i++){
res +=dp[a[i]][b[i]];
}
printf("%I64d\n",res);
}
return 0;
}
/*
1 2
3 5
7 10
6 8
1 2
3 5
10 7
8 6
*/