Problem Descriptionezio Auditore is a great master as an assassin. Now he had prowled in the enemies ' base successfully. He finds that's the only weapon he can use was his cuff sword and the sword have durability m. There is n enemies he wants to kill and killing each enemy needs Ai durability. Every time Ezio kills an enemy he can use the enemy's sword to kill any other Bi enemies without wasting his cuff sword ' s Durability. Then the enemy ' s sword would break. As a master, Ezio always want to do things perfectly. He decides to kill as many enemies as he can using the minimum durability cost.
Inputthe first line contains an integer T, the number of test cases.
For each test case:
The first line contains the integers, above mentioned N and M (1<=n<=10^5, 1<=m<=10^9).
Next n lines, each line contains the integers Ai, Bi. (0<=ai<=10^9, 0<=bi<=10).
Output
For each case, output ' Case x: ' (x is the case number starting from 1) followed by the number of the enemies Ezio can Kil L and the minimum durability cost.
Sample Input23 0 Sample Outputcase 1:3 4 case 2:0 0
Approximate test instructions:Kill
with M-point endurance, kill a person requires AI endurance, but the acquired weapon can kill the bi personally.
The topic requires the first to kill the most, followed by the least durability of consumption.
Problem Solving Ideas:
Greedy
If you can kill a sword:
Kill a sword first, and a sword can be killed.
After getting all the swords, the number of swords is fixed, so the number of people killed with swords is fixed, killing everyone is the same;
Since the sword to kill who are the same, then do not use the sword to kill the minimum durability;
So according to the consumption of durable from the small to the big sort, kill the past to kill until not move.
What if there is a sword in it? Nothing to do, he himself was killed by the consumption of durable, the original sword killed his can kill others, with the number of sword kill are fixed;
What if there is no sword on this side? The first to kill a sword is the least durable;
If you can't kill a sword:
or according to the durability from the small to the big sort, one by one to kill the past until the killing.
Comprehensive:
If you can kill a sword, that has the sword of the durability of the smallest kill, the answer to add the number of swords
If you can't kill a sword, don't kill it:
Residual durability is to kill the minimum durability, pay attention to the first to kill the possible inside of the sword, it will skip;
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 #defineN 1000105 structenemy{intb;} T[n];6 BOOLCMP (enemy X,enemy y) {returnx.a<y.a;}7 intMain () {8 intt,n,m,cas=1;9scanf"%d",&T);Ten while(t--){ One inti,cost=0, num=0, k=-1; Ascanf"%d%d",&n,&m); - for(i=0; i<n;i++) scanf ("%d%d",&t[i].a,&t[i].b); -Sort (t,t+n,cmp); the for(i=0; i<n;i++)if(T[I].B) Break;//looking for cost_min,b!=0. - if(t[i].a<=m) { -cost+=t[k=i].a; - for(num++,i=0; i<n;i++) num+=t[i].b;//a sword, a sword of all death, a sword all taken, sword homicide number fixed +}if(num>=n) {printf ("Case %d:%d%d\n", cas++,n,cost);Continue;} - for(i=0; i<n&&t[i].a+cost<=m&&num!=n;i++)if(i!=k) cost+=t[i].a,num++; +printf"Case %d:%d%d\n", cas++, num,cost); A}return 0; at}
HDU 4415-assassin ' s Creed