#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
//const long long MAXN = 9223372036854775807;
typedef struct beast{
int a;
int b;
}Beast;
typedef struct power{
int k;
int p;
}Power;
Power powe[1001];
Beast bea[100001];
int dp[11][1001][1001];
int main()
{
int n, m;
int i, j, k;
int offense;
int count = 0;
// bool vis[100001];
while (scanf("%d%d", &n, &m) != EOF)
{
long long sum=0;
for (i = 0; i < n; i++)
scanf("%d%d", &bea[i].a, &bea[i].b);
for (i = 0; i < m; i++)
scanf("%d%d", &powe[i].k, &powe[i].p);
for (k = 0; k <= 10; k++)//k表示防御值
{
for (i = 0; i < m; i++)
{
offense = powe[i].p - k;
for (j = 0; j <= 1000; j++)
{
if (offense <= 0)
{
if (i >= 1)
dp[k][i][j] = dp[k][i - 1][j];
else
dp[k][i][j] = INT_MAX;
continue;
}
if (i == 0 && j != 0)
{
while (count*offense < j)
{
count++;
}
dp[k][i][j] = count*(powe[i].k);
count = 0;
}
else if (j == 0)
dp[k][i][j] = 0;
else
{
dp[k][i][j] = dp[k][i - 1][j];
if (j >= offense)
dp[k][i][j] = min(dp[k][i][j - offense] + powe[i].k, dp[k][i][j]);
else
dp[k][i][j] = min(powe[i].k, dp[k][i][j]);
}
}
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)//和所有晶石攻击大小比较
{
if (bea[i].b < powe[j].p)
break;
}
if (j == m)
{
printf("-1\n");
break;
}
else
sum += dp[bea[i].b][m - 1][bea[i].a];
}
if (i == n)
printf("%lld\n", sum);
}
// system("pause");
return 0;
}
转载于:https://www.cnblogs.com/wangzao2333/p/7327747.html