# 度度熊与邪恶大魔王

Accepts: 2033

Submissions: 12471
Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)
Problem Description

Input

1<=n<=100000

1<=m<=1000

1<=a[i]<=1000

0<=b[i]<=10

0<=k[i]<=100000

0<=p[i]<=1000

Output

Sample Input
1 2
3 5
7 10
6 8
1 2
3 5
10 7
8 6

Sample Output
6
18
想法：完全背包
代码：
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
#define INF 0x3f3f3f3f
long long a[100010],b[100010];
long long k[1010];
long long p[1010];
long long dp[1010][15];
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
int i,j,k1;
long long maxx=0,maxn=0, mass=0;
for(i=0;i<n;i++)
{
scanf("%I64d %I64d",&a[i],&b[i]);
maxx=max(maxx,b[i]);
mass=max(mass,a[i]);
}
for(i=0;i<m;i++)
{
scanf("%I64d %I64d",&k[i],&p[i]);
maxn=max(maxn,p[i]);
}
if(maxn<=maxx)
{
printf("-1\n");
continue;
}
memset(dp,0,sizeof(dp));
for(i=0;i<=10;i++)//防御
{
for(j=1;j<=mass;j++)//造成伤害
{
dp[j][i]=INF;
for(k1=0;k1<m;k1++)//第k1个技能
{
long long dm=p[k1]-i;
if(dm<=0)
continue;
if(dm>j)
{
dp[j][i]=min(dp[j][i],k[k1]);
}
else
{
dp[j][i]=min(dp[j][i],dp[j-dm][i]+k[k1]);
}
}
}
}
long long sum=0;
for(i=0;i<n;i++)
{
sum+=dp[a[i]][b[i]];
}
printf("%I64d\n",sum);
}
return 0;
}