水题,水题,不多说。每次选择最便宜的就可以了。
/**
TASK: milk
ID: DickensTone
LANG: C++
**/
#include<cstdio>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 5000 + 5;
struct node
{
int cents;
int tot;
bool operator < (const node &a) const
{
return cents < a.cents;
}
}pre[maxn];
int main()
{
freopen("milk.in", "r", stdin);
freopen("milk.out", "w", stdout);
int n, m;
while(scanf("%d%d", &n, &m) == 2)
{
int ans = 0;
for(int i = 0; i < m; i++)
{
scanf("%d%d", &pre[i].cents, &pre[i].tot);
}
sort(pre, pre + m);
for(int i = 0; i < m && n; i++)
{
int t = min(n, pre[i].tot);
ans += t * pre[i].cents;
n = n - t;
}
printf("%d\n", ans);
}
return 0;
}