水题
#include<iostream> #include<algorithm> using namespace std; #define LL long long const int maxn=1e5+10; struct node{int x, y;}a[maxn]; bool cmp(node a, node b){ return a.x-a.y>b.x-b.y; } LL n, m, len, ans, ans1; int main(){ cin>>n>>m; for(int i=0;i<n;++i){ cin>>a[i].x>>a[i].y; ans+=a[i].x; ans1+=a[i].y; } if(ans<=m){cout<<0<<endl; return 0;} if(ans1>m){cout<<-1<<endl; return 0;} else if(ans1==m){cout<<n<<endl; return 0;} sort(a, a+n, cmp); for(int i=0;i<n;++i){ ans=ans-a[i].x+a[i].y; ++len; if(ans<=m)break; } cout<<len<<endl; return 0; }