P1208
求条awa
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
}a[5005];
bool cmp(node a,node b){
return a.x<b.x;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, cnt;
cin >> n >> m;
for (int i = 1; i <= m; i ++) {
cin >> a[i].x >> a[i].y;
}
sort (a + 1, a + m + 1, cmp);
for (int i = 1; i <= m; i ++) {
if (a[i].y <= n) {
cnt += a[i].x * a[i].y;
n -= a[i].y;
}
else {
cnt += a[i].x * (a[i].y - n);
n = 0;
}
if (n == 0) {
break;
}
}
cout << cnt;
}