提交时间:2023-11-02 13:37:17
运行 ID: 108362
#include<algorithm> #include<iostream> using namespace std; struct P{ int v,w; bool operator < (const P &q) const{ return v < q.v; } }s[5005]; int main(){ long long n,m,money = 0,o = 0; cin>>n>>m; for (int i = 0;i < m;i++){ cin>>s[i].v>>s[i].w; } if (n == 0 && m == 0){ cout<<0<<endl; //qwq return 0; } sort(s,s + m); for (int i = 0;i < m;i++){ for (int j = 1;j <= s[i].w;j++){ money += s[i].v; n--; if (n <= 0){ cout<<money<<endl; return 0; } } } cout<<money<<endl; return 0; }