提交时间:2023-11-04 11:28:56
运行 ID: 108891
#include<bits/stdc++.h> using namespace std; struct milk {int price,num;}m[5555]; bool cmp(milk x,milk y) {return x.price<y.price;} int total,cost,need,farmer; int main() { cin>>need>>farmer; for(int i=1;i<=farmer;i++) {cin>>m[i].price>>m[i].num;} sort(m+1,m+1+farmer,cmp); for(int i=1;i<=farmer;i++) { cost+=m[i].num; total+=m[i].num*m[i].price; if(cost>need) {total-=(cost-need)*m[i].price;cout<<total;return 0;} } }