题目地址:http://cerberus.delosent.com:791/usacoprob2?a=Gk9WloAo5kd&S=milk2
中文题目链接:http://www.nocow.cn/index.php/Translate:USACO/milk
思路比较简单直接结构体排序+贪心
/*
PROG: milk
LANG: C++11
*/
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
typedef long long ll;
const int maxn = 200100;
const ll mod = 1000000007;
struct node {
int price;
int unit;
} a[5005];
int n , m;
// not needed
bool cmp(node n1, node n2){
return n1.price < n2.price;
}
int main()
{
ifstream fin ("milk.in");
ofstream fout ("milk.out");
fin >> n >> m;
cout << n << m << endl;
for(int i = 1; i <= m ;i++){
int p, u;
fin >> p >> u;
a[i].price = p; a[i].unit = u;
}
sort(a+1, a+1+m, cmp);
ll sum = 0;
for(int i = 1; i <= m ; i++){
if ( n <= a[i].unit){
sum += a[i].price * n;
break;
}
else{
sum += a[i].price * a[i].unit;
n -= a[i].unit;
}
}
fout << sum << endl;
fin.close();
fout.close();
return 0;
}