正文
增加 8 行删除 8 行
49 行未改动505152535455565758596061626364656667686970717273747576773 行未改动49 行未改动signed main(){scanf("%lld%lld%lld",&n,&m,&p);for(int i=1;i<=n;i++) scanf("%lld%lld",&c[i].a,&c[i].b),c[i].v=c[i].a-c[i].b;sort(c+1,c+1+n,cmp); //按 c 升序排序//购买前 k 头牛for(int i=1;i<=m;i++){if(sum+c[i].b<=p) sum+=c[i].b,q.push(c[i].v);else printf("%lld",i-1),exit(0); //前 k 头牛都买不完直接退出}fcost=scost=sum,fans=sans=m;//上文中的情况 2for(int i=m+1;i<=n;i++){//直接买更便宜if(c[i].a<=c[i].b+q.top()&&fcost+c[i].a<=p) fcost+=c[i].a,fans++;//将优惠券进行转移if(c[i].b+q.top()<c[i].a&&fcost+q.top()+c[i].b<=p){fcost+=c[i].b+q.top(),fans++;q.pop(),q.push(c[i].v);}}//复用堆,节省空间while(q.size()) q.pop();//上文中的情况 1for(int i=m+1;i<=n;i++) q.push(c[i].a);while(q.size()&&scost+q.top()<=p) scost+=q.top(),q.pop(),sans++;printf("%lld",max(fans,sans));return 0;3 行未改动49 行未改动505152535455565758596061626364656667686970717273747576773 行未改动49 行未改动signed main(){scanf("%lld%lld%lld",&n,&m,&p);for(int i=1;i<=n;i++) scanf("%lld%lld",&c[i].a,&c[i].b),c[i].v=c[i].a-c[i].b;sort(c+1,c+1+n,cmp); //按 c 升序排序//购买前 k 头牛for(int i=1;i<=m;i++){if(sum+c[i].b<=p) sum+=c[i].b,q.push(c[i].v);else printf("%lld",i-1),exit(0); //前 k 头牛都买不完直接退出}fcost=scost=sum,fans=sans=m;//上文中的情况 2for(int i=m+1;i<=n;i++){//直接买更便宜if(c[i].a<=c[i].b+q.top()&&fcost+c[i].a<=p) fcost+=c[i].a,fans++;//将优惠券进行转移if(c[i].b+q.top()<c[i].a&&fcost+q.top()+c[i].b<=p){fcost+=c[i].b+q.top(),fans++;q.pop(),q.push(c[i].v);}}//复用堆,节省空间while(q.size()) q.pop();//上文中的情况 1for(int i=m+1;i<=n;i++) q.push(c[i].a);while(q.size()&&scost+q.top()<=p) scost+=q.top(),q.pop(),sans++;printf("%lld",max(fans,sans));return 0;3 行未改动