用的结构体:单位时间采药的价格最大优先采集
代码如下:```cpp
#include<bits/stdc++.h>
using namespace std;
int t,m;
struct yao{
int tim;
int price;
int dp;
}y[10009];
bool cmp(yao x,yao y){
if(x.dp==y.dp) return x.price>y.price;
return x.dp>y.dp;
}
int main(){
cin>>t>>m;
for(int i=1;i<=m;i++){
cin>>y[i].tim>>y[i].price;
y[i].dp=(y[i].price<<15)/y[i].tim;
}
sort(y+1,y+m+1,cmp);
long long ans=0;
for(int j=1;j<=m;j++){
if(y[j].tim<=t){
ans+=t/y[j].tim*y[j].price;
t%=y[j].tim;
}
}
cout<<ans;
return 0;
}