#include<bits/stdc++.h> usingnamespace std; // https://www.luogu.com.cn/problem/P1208 structnode { int p; //价格 int t; //拥有的数量 } man[100000]; boolcmp(node a, node b) { return a.p < b.p; } intmain() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> man[i].p >> man[i].t; } sort(man + 1, man + 1 + m, cmp); longlong ans = 0; int cnt = 0; while (n) { if (n > man[++cnt].t) { ans += man[cnt].p * man[cnt].t; n -= man[cnt].t; } else { ans += man[cnt].p * n; n = 0; } } cout << ans; return0; }