提交时间:2023-11-08 21:43:13
运行 ID: 109467
#include<bits/stdc++.h> using namespace std; struct nongmin{ int jiage,shuliang; }a[5005]; bool cmp(nongmin a,nongmin b){ return a.jiage<b.jiage; } int n,m,cnt=1,ans; int main(){ cin>>n>>m; for(int i=1;i<=m;i++){ cin>>a[i].jiage>>a[i].shuliang; } sort(a+1,a+m+1,cmp); while(n--){ if(!a[cnt].shuliang)cnt++; ans+=a[cnt].jiage; a[cnt].shuliang--; } cout<<ans; return 0; }