您的位置:首页 > 其它

sicily 1134.积木分发

2013-10-24 20:19 417 查看
策略:按小朋友所需积木块数从小到大排序

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Info
{
int have;
int need;
Info(int a,int b)
{
this->have = a;
this->need = b;
}
Info()  {}
};

bool com(Info a,Info b)
{
return a.need < b.need;
}

int main()
{
int n,m,i;
vector<Info> data;
int a,b;
while(cin >> n >> m && n != 0)
{
data.clear();
for(i = 0;i < n;i++)
{
cin >> a >> b;
data.push_back(Info(a,b));
}
sort(data.begin(),data.end(),com);
int temp = m;
for(i = 0;i < n;i++)
{
if(temp < data[i].need)
break;
else
temp += data[i].have;

}

if(i < n)
cout << "NO" << endl;
else
cout << "YES" << endl;

}

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