InputOn the first line one positive number: the number of testcases, at most 100. After that per testcase:
One line with two integers: 1 ≤ n ≤ 1 000, the number of available components and 1 ≤ b ≤ 1 000 000 000, your budget.
n lines in the following format: 「type name price quality」, where type is a string with the type of the component, name is a string with the unique name of the component, price is an integer (0 ≤ price ≤ 1 000 000) which represents the price of the component and quality is an integer (0 ≤ quality ≤ 1 000 000 000) which represents the quality of the component (higher is better). The strings contain only letters, digits and underscores and have a maximal length of 20 characters.
OutputPer testcase:
One line with one integer: the maximal possible quality.Sample Inputnode
1 18 800 processor 3500_MHz 66 5 processor 4200_MHz 103 7 processor 5000_MHz 156 9 processor 6000_MHz 219 12 memory 1_GB 35 3 memory 2_GB 88 6 memory 4_GB 170 12 mainbord all_onboard 52 10 harddisk 250_GB 54 10 harddisk 500_FB 99 12 casing midi 36 10 monitor 17_inch 157 5 monitor 19_inch 175 7 monitor 20_inch 210 9 monitor 22_inch 293 12 mouse cordless_optical 18 12 mouse microsoft 30 9 keyboard office 4 10
Sample Outputios
9
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <cstdlib> 7 #include <iomanip> 8 #include <cmath> 9 #include <ctime> 10 #include <map> 11 #include <set> 12 using namespace std; 13 #define lowbit(x) (x&(-x)) 14 #define max(x,y) (x>y?x:y) 15 #define min(x,y) (x<y?x:y) 16 #define MAX 100000000000000000 17 #define MOD 1000000007 18 #define pi acos(-1.0) 19 #define ei exp(1) 20 #define PI 3.141592653589793238462 21 #define INF 0x3f3f3f3f3f 22 #define mem(a) (memset(a,0,sizeof(a))) 23 typedef long long ll; 24 const int N=1005; 25 const int mod=1e9+7; 26 int value[N],k,n,m,t; 27 struct Node 28 { 29 char type[30]; 30 char name[30]; 31 int cost,val; 32 friend bool operator<(const Node&a,const Node&b){ 33 if(strcmp(a.type,b.type)==0) return a.val==b.val?a.cost<b.cost:a.val>b.val; 34 return strcmp(a.type,b.type)<0; 35 } 36 }node[N]; 37 vector<Node>v[N]; 38 bool check(int mid) 39 { 40 ll ans=0; 41 for(int i=0;i<k;i++){ 42 int pos=mod; 43 for(int j=0;j<v[i].size();j++){ 44 if(v[i][j].val>=mid) pos=min(pos,v[i][j].cost); 45 } 46 ans+=pos; 47 if(ans>m)return 0; 48 } 49 return 1; 50 } 51 int main() 52 { 53 scanf("%d",&t); 54 while(t--){ 55 scanf("%d%d",&n,&m); 56 k=0; 57 for(int i=0;i<n;i++){ 58 v[i].clear(); 59 scanf("%s %s %d %d",&node[i].type,&node[i].name,&node[i].cost,&node[i].val); 60 value[i]=node[i].val; 61 } 62 sort(value,value+n); 63 sort(node,node+n); 64 for(int i=0;i+1<n;i++){ 65 while(i+1<n&&strcmp(node[i].type,node[i+1].type)==0){ 66 v[k].push_back(node[i]); 67 i++; 68 } 69 v[k].push_back(node[i]); 70 k++; 71 } 72 int l=0,r=n-1; 73 int mid=(r+l)>>1; 74 while(l<=r){ 75 if(check(value[mid])) l=mid+1; 76 else r=mid-1; 77 mid=(l+r)>>1; 78 } 79 printf("%d\n",value[mid]); 80 } 81 return 0; 82 }