水题
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 5e3 + 10;
struct prc
{
int price, val;
}arr[MAXN];
bool cmp(prc a, prc b)
{
return a.price < b.price;
}
int main()
{
int sum , N, ans = 0;
cin>>sum>>N;
for(int i = 0; i < N; i++)
cin>>arr[i].price>>arr[i].val;
sort(arr, arr + N, cmp);
for(int i = 0; i < N; i++)
{
if(sum - arr[i].val >= 0)
{
ans += arr[i].val * arr[i].price;
sum -= arr[i].val;
}
else
{
ans += sum * arr[i].price;
goto l1;
}
}
l1:
cout<<ans<<endl;
return 0;
}