Today the Intergalactic Council of Pebble Coins (ICPC) conducted an intergalactic auction of the Neutronium Chaos Pebble Coin (NCPC). This coin, which was forged in the Ancient Coin Machine (ACM), is rumored to be the key to ruling the universe.
Due to the extremely competitive nature of the auction, as well as the odd mechanics of the intergalactic currency used (far too advanced for mere mortals to understand), the auction was conducted with the following rules:
only one participant was allowed to make a bid at a time,
each participant was only allowed to make one bid, and
a participant making a bid had to bid at least twice the amount of the highest bid at the time.
The first participant making a bid was allowed to make a bid of any positive amount.
After the auction there were a lot of sore losers -- understandably, having just lost their chance at world domination. To make the losers feel a little better and prevent possible rioting, the ICPC has decided to hold a lottery for the participants. The winners of the lottery are determined as follows. The ICPC picks a random number s. A group of participants is called winning if the sum of their bets from the auction is equal to s. A participant wins the lottery and receives a prize -- a shiny Pebble Coin -- if they belong to any winning group of participants.
Given the names of the participants, the bets that they made, and the random number s chosen by the ICPC, help them determine which participants won the lottery.
The first line of input contains two integers n and s, where 1 ≤ n ≤ 1 000 is the number of participants, and 1 ≤ s < 101 000 is the random number chosen by the ICPC.
Then follow n lines describing the participants. Each line contains a string t and an integer b, where t is the name of a participant, and 1 ≤ b < 101 000 is the amount of his bet. The name of each participant is unique and consists of between 1 and 20 letters from the English alphabet.
Output an integer k denoting the number of participants that won the lottery. Then output k lines containing the names of the participants that won the lottery, one per line, in any order.
5 63
Vader 3
Voldemort 7
BorgQueen 20
Terminator 40
Megatron 101
---------------------------
4 1112
Blorg 10
Glorg 1000
Klorg 1
Zlorg 100
3
BorgQueen
Terminator
Vader
---------------------
0
题意:直接解释样例。输入两个数 n 和 s ,接着有 n 个姓名 与 其 权值w。 问是否可以从 n 个 w 中选出若干个 使其和为 s. 能则输出这若干个姓名,不能则输出 0 。 / 注意!!!这 n 个 w 从小到大排序后 相邻的两个 w 至少相差两倍以上
思路:先将 w 按小到大排序,由于 相差两倍以上这一点,你会发现,必须取 s 小于的第一个 w 的前一个数 设为 x,不然不可能构成和为 s ,所以每一次都找出 x,然后用 s -= x, 再重复寻找。。。。
//EMMMMMMM,中南的OJ 这个题没有SPJ,而且 不能sort
#include
#define fuck(x) std::cout<<"["<<#x<<"->"<= 0) {
if(c[i] < 0) {
c[i] += 10;
c[i - 1] -= 1;
}
f[x++] = c[i];
i--;
}
int p = 0;
if(f[x - 1] == 0)
flag = 0;
for(int y = x - 1; y >= 0; y--) {
if(f[y] != 0)
flag = 1;
if(flag == 1)
tmpj[p ++] = f[y] + '0';
}
if(flag == 0)
tmpj[p ++] = '0';
tmpj[p] = '\0';
}
int main()
{
int n;
while(~scanf("%d",&n)){
char str[maxn]; scanf("%s",str);
for(int i = 1;i <= n;++ i)
scanf("%s %s",a[i].name,a[i].num);
sort(a + 1,a + 1 + n,cmp);
vectorans;
while(1){
//fuck(str);
if(str[0] == '0') break;
if(n == 0) break;
int i;
for(i = 1;i <= n;++ i){
if(ok(str,a[i].num) == 1){
if(i == 1){
n = 0;
break;
}
ans.push_back(a[i - 1].name);
bigjian(str,a[i - 1].num);
strcpy(str,tmpj);
n = i - 1;
break;
}
else if(i == n){
ans.push_back(a[i].name);
bigjian(str,a[i].num);
strcpy(str,tmpj);
n = i - 1;
}
}
}
//cout << str<< endl;
if(str[0] == '0'){
int p=ans.size();
printf("%d\n",p);
// sort(ans.begin() ,ans.end());
for(auto x:ans)
cout << x << endl;
}
else printf("0\n");
}
return 0;
}