标签:
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
#define CLR(x,y) memset((x),(y),sizeof((x)))
#define CLR2(x,y,mtype,mcnt) memset((x),(y),sizeof((mtype))*(mcnt))
#define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x))
#define FORD(x,y,z) for(int (x)=(y);(x)>=(z);--(x))
const int maxn = 1000 + 100;
struct Com{
int price,quality;
Com(int p = 0,int q = 0):price(p),quality(q){}
};
vector<Com> comp[maxn];
map<string,int> id;
int t,n,b,p,q,maxq,cnt;
int ID(string str){
if(id.count(str)) return id[str];
else id[str] = cnt;
return cnt++;
}
int ok(int q){
int sum = 0;
FOR(i,0,cnt){
int chepest = b + 1;
int m = comp[i].size();
FOR(j,0,m){
if(comp[i][j].quality >= q && comp[i][j].price < chepest)
chepest = comp[i][j].price;
}
sum += chepest;
if(sum > b) return 0;
}
return 1;
}
int main(){
char type[30];
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&b);
cnt = 0;
FOR(i,0,n) comp[i].clear();
id.clear();
maxq = 0;
FOR(i,0,n){
scanf("%s %*s %d %d",type,&p,&q);
if(q > maxq) maxq = q;
comp[ID(type)].push_back( Com(p,q) );
}
int l = 0,r = maxq,mid;
while(l < r){
mid = l + (r - l + 1)/2;
if(ok(mid)) l = mid;
else r = mid - 1;
}
printf("%d\n",l);
}
return 0;
}
[2016-03-19][UVALive][3971][Assemble]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/5756d173066a1bbc57c758d0c26452fe.html