[http://codeforces.com/contest/1015/problem/C]
一道结构体排序题,数据很水,给定的数据居然是左边一定大于右边,注意数组开大。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
ll l,r,x;
}no[100005];
bool cmp(node a,node b){
return a.x>b.x;
}
ll big = 0,sma = 0;
ll n,m;
int main(){
while(cin>>n>>m){
for(ll i=0;i<n;i++){
cin>>no[i].l>>no[i].r;
big+=no[i].l;
sma+=no[i].r;
no[i].x = no[i].l-no[i].r;
}
ll t = 0;
if(sma>m) cout<<-1<<endl;
else if(big<=m) cout<<0<<endl;
else {
sort(no,no+n,cmp);
for(ll i=0;i<n;i++){
big-=no[i].x;
t++;
if(big<=m) break;
}cout<<t<<endl;
}
}
return 0;
}