AcWing 1348. 搭配牛奶
原题链接
简单
作者:
Vason
,
2024-04-14 21:15:23
,
所有人可见
,
阅读 5
关键字重排序
#include <iostream>
#include <cstring>
#include <algorithm>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e6 + 10;
PII a[N];
int n, m;
int main()
{
scanf("%d%d", &m, &n);
for(int i = 0; i < n; i ++) scanf("%d%d", &a[i].x, &a[i].y);
sort(a, a + n);
LL res = 0;
for(int i = 0; i < n; i ++)
{
if(m >= a[i].y) res += (LL)a[i].y * a[i].x, m -= a[i].y;
else
{
res += (LL)m * a[i].x;
break;
}
}
printf("%lld", res);
return 0;
}