#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1005;
const int MAXC = 35;
int d[MAXC];
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int T, n, p, w;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
memset(d, 0, sizeof(d));
for(int i=1; i<=n; i++) {
scanf("%d%d", &p, &w);
for(int j=30; j>=w; j--) {
if(d[j] < d[j-w]+p) {
d[j] = d[j-w]+p;
}
}
}
int sum = 0;
int g, c;
scanf("%d", &g);
for(int i=0; i<g; i++) {
scanf("%d", &c);
sum += d[c];
}
printf("%d\n", sum);
}
}
UVa 10130 - SuperSale
最新推荐文章于 2016-03-18 23:27:00 发布
