You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
884 B
33 lines
884 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
typedef long long LL;
|
|
int n, m;
|
|
const int N = 5010;
|
|
LL cost;
|
|
|
|
struct cow {
|
|
int price, cnt; //price:表示第i个农民牛奶的单价,cnt:农民i一天最多能卖出的牛奶量
|
|
} cows[N];
|
|
|
|
bool cmp(const cow &a, const cow &b) {
|
|
return a.price < b.price;
|
|
}
|
|
|
|
int main() {
|
|
cin >> n >> m; //需要牛奶的总量,和提供牛奶的农民个数。
|
|
for (int i = 1; i <= m; i++) cin >> cows[i].price >> cows[i].cnt;
|
|
sort(cows + 1, cows + m + 1, cmp);
|
|
|
|
for (int i = 1; i <= m; i++) {
|
|
for (int j = 1; j <= cows[i].cnt; j++)
|
|
if (n) n--, cost += cows[i].price;
|
|
else {
|
|
cout << cost << endl;
|
|
exit(0);
|
|
}
|
|
}
|
|
//因为存在败家的测试数据: 0 0 ,不得不防啊
|
|
cout << cost << endl;
|
|
return 0;
|
|
} |