5
6 2 7
5 4 9
1 2 4
2 5 8
1 3 9
5
2 7 1
2 7 2
3 2 0
5 7 2
4 1 5
TAK
NIE
TAK
TAK
NIE
#include<bits/stdc++.h>
using namespace std;
const int maxv = 1e6+10;
int n,m,sum;
int f[maxv * 10];
int ans[maxv * 10];
struct node{
int a,b,c;
}a[maxv];
struct Node{
int m,k,s,id;
}b[maxv * 10];
bool cmp(node a,node b){return a.a < b.a;}
bool Cmp(Node a,Node b){return a.m < b.m;}
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;++i)scanf("%d%d%d",&a[i].c,&a[i].a,&a[i].b);
scanf("%d",&m);
for(int i = 1;i <= m;++i){
scanf("%d%d%d",&b[i].m,&b[i].k,&b[i].s);
b[i].id = i;//记录询问顺序防止排序排乱
}
sort(a + 1,a + n + 1,cmp);
sort(b + 1,b + m + 1,Cmp);
f[0] = 0x3f3f3f3f;
int j = 1;
for(int i = 1;i <= m;++i){
while(j <= n && a[j].a <= b[i].m){
for(int k = 100000;k >= a[j].c;--k)
f[k] = max(f[k],min(f[k - a[j].c],a[j].b));
++j;
}
if(f[b[i].k] > b[i].m + b[i].s)ans[b[i].id] = 1;//如果最小的都满足
}
for(int i = 1;i <= m;++i){
if(ans[i])printf("TAK\n");
else printf("NIE\n");
}
}
P3537 [POI2012]SZA-Cloakroom (背包)
原文:https://www.cnblogs.com/2004-08-20/p/13338526.html