不能及时回复,还请谅解
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=1e4+5;
struct node{
int v,w;
double c;
}med[maxm];
bool cmp(node a,node b){
if(a.c==b.c){
return a.v<b.v;
}
return a.c>b.c;
}
int m,t,total;
signed main(){
cin>>t>>m;
for(int i=1;i<=m;i++){
cin>>med[i].v>>med[i].w;
med[i].c=med[i].w*1.0/med[i].v;
}
sort(med+1,med+1+m,cmp);
for(int i=1;i<=m;i++){
if(t<=0){
break;
}else{
int tmp=t/med[i].v;
total+=tmp*med[i].w;
t-=tmp*med[i].w;
}
}
cout<<total;
return 0;
}