您的位置:首页 > 其它

Sicily 1134 积木分发

2013-01-05 17:27 525 查看
/*
把所有孩子按照需要积木的量从小到大排序,依次加上歌星手里的积木即可
还以为用long会不够精度,结果居然过了
*/
/*
Passed all 4 test cases
Run Time: 0.31secs
Run Memory: 444KB
*/

#include <iostream>
#include <algorithm>    //sort等
#include <vector>

using namespace std;

typedef struct Child{
long a;  //孩子拥有的木头数
long b;  //孩子还需要的木头数
};
vector<Child> children;

int cmp(Child a, Child b){
return a.b < b.b;
}

long N;  //孩子数 1-10000
long S;  //歌星拥有木头数 1-1000000

void compute(){
sort(children.begin(), children.end(), cmp);

for(int i=0; i<children.size(); i++){
if(S >= children[i].b){
S += children[i].a;
}else{
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}

int main()
{
while (cin>>N && N){
cin >> S;

if(children.size() != 0)
children.clear();

for(int i=0; i<N; i++){
Child buf;
cin >> buf.a >> buf.b;
children.push_back(buf);
}

compute();
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: