Description
有nn种千里马,每一种都有若干匹,第ii种马的颜值a_ia
i
,价格d_id
i
.现有mm个牧马人要去挑选千里马,每一位牧马人对马的颜值都有要求:{所选马的颜值总和} \geqslant A_i⩾A
i
.现在让你来为牧马人做满足要求的最低预算.
Input
单组测试数据,第一行两个整数n,mn,m,( 1 \leq n,m \leq 1e4)(1≤n,m≤1e4).
接下来nn行,每行两个整数a_1,d_1,a_2,d_2,…a_n,d_na
1
,d
1
,a
2
,d
2
,…a
n
,d
n
.
最后一行mm个整数A_1,A_2,…A_mA
1
,A
2
,…A
m
,( 1 \leq a_i,d_i,A_i \leq 1e4)(1≤a
i
,d
i
,A
i
≤1e4).
Output
输出mm个整数占一行,用空格隔开,表示每一位牧马人的最低花费.
Sample Input 1
2 2
1 2
2 1
5 5
Sample Output 1
3 3
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define met(s) memset(s, 0, sizeof(s))
#define rep(i, a, b) for(int i = a; i <= b; ++i)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAXN = 1e4 + 10;
int A[MAXN];
int a[MAXN], d[MAXN];
int dp[MAXN];
int main() {
// freopen("5.in", "r", stdin);
// freopen("5.out", "w", stdout);
int n, m;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) scanf("%d %d", &a[i], &d[i]);
dp[0] = 0;
for(int i = 1; i <= 10005; ++i) {
dp[i] = INF;
for(int j = 0; j < m; ++j) {
if(i <= a[j]) dp[i] = min(d[j], dp[i]);
else dp[i] = min(dp[i], dp[i - a[j]] + d[j]);
}
}
for(int i = 0; i < m; ++i) {
scanf("%d", &A[i]);
printf("%d%c", dp[A[i]], (i == m - 1) ? '\n' : ' ');
}
return 0;
}