随笔-141  评论-9  文章-3  trackbacks-0

/*
ID: lorelei3
PROG: milk
LANG: C++
*/


#include 
<fstream>
#include 
<algorithm>

using namespace std;

const int MAX = 5005;

typedef 
struct Cow{
    
int price;
    
int amount;
    
bool operator< (const Cow& c) const{
        
return price < c.price;
    }

}
Cow, *pCow;

Cow cows[MAX];

int total,n;

int main(){
    
int i, cost=0;
    ifstream 
in("milk.in");
    ofstream 
out("milk.out");

    
in>>total>>n;

    
for(i=0; i<n; ++i){
        
in>>cows[i].price>>cows[i].amount;
    }


    sort(cows, cows
+n);

    i
=0;
    
while(total-cows[i].amount>0){
        total 
-= cows[i].amount;
        cost 
+= cows[i].amount * cows[i].price;
        i
++;
    }


    cost 
+= cows[i].price*total;

    
out<<cost<<endl;

    
return 0;
}
posted on 2010-11-09 00:59 小阮 阅读(116) 评论(0)  编辑 收藏 引用 所属分类: USACO

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理