#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<
int,
int> pii;
std::
vector<pii> v;
bool cmp(
const pii &a,
const pii &b) {
return a.first < b.first;
}
int main(
int argc,
char const *argv[]) {
ofstream fout (
"milk.out");
ifstream fin (
"milk.in");
int n, m;
fin >> n >> m;
while (m--) {
int pi, ai;
fin >> pi >> ai;
v.push_back(make_pair(pi, ai));
}
sort(v.begin(), v.end(), cmp);
int u =
0, tc =
0;
for (
int i =
0; i < v.size(); ++i) {
int pi = v[i].first, ai = v[i].second;
if (u < n) {
int ub = min(n-u, ai);
u+=ub;
tc+=ub*pi;
}
else {
break;
}
}
fout << tc << endl;
return 0;
}
评注:
假设最高价格为MAXP,那么可以设一个MAXP大小的数组以减少用于排序的时间
转载请注明原文地址: https://ju.6miu.com/read-1296888.html