'commit'
This commit is contained in:
33
TangDou/LuoGuBook/P1208.cpp
Normal file
33
TangDou/LuoGuBook/P1208.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user