#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int n, m;
struct node {
int a, b;
}p[N];
bool cmp(node x, node y)
{
return x.a <= y.a;
}
int main()
{
scanf("%d %d", &n, &m);
if (n == 0)
{
cout << 0;
return 0;
}
for (int i = 1; i <= m; i ++ )
cin >> p[i].a >> p[i].b;
sort(p + 1, p + 1 + m, cmp);
long long ans = 0;
for (int i = 1; i <= m; i ++ )
{
if (n >= p[i].b)
{
ans += (long long)(p[i].a * p[i].b);
n -= p[i].b;
}
else
{
ans += (long long)(n * p[i].a);
break;
}
}
printf("%lld", ans);
return 0;
}
把cmp函数里的该成
x.a < y.a
就对了,这是为什么