#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
const int MAXN = 10000 + 10;
const int MAXM = 1000000000 + 1000;
typedef long long LL;
/*
HDU 3090
注意: vector.end()是超尾结点, 即尾元素之后的那个元素而非最后一个元素, 是无意义的
*/
int main(){
int N,M;
scanf("%d %d",&N,&M); // N:number of roads, M:coins for guard
while( !(N==0 && M==0) ){
int D,P; // D:length, P:robbers
multimap<int,int> m;
for(int i=0; i<N; i++){
scanf("%d %d",&D,&P);
m.insert(pair<int,int>(P,D));
}
multimap<int,int>::reverse_iterator rt = m.rbegin();
while( M>0 && rt!=m.rend() ){
// cout << "first=" << (*it).first << ", second=" << (*it).second << endl;
// cout << "M=" << M << endl;
if( M>(*rt).second ){
M -= (*rt).second;
(*rt).second = 0;
rt++;
}else{
(*rt).second -= M;
M = 0;
break;
}
}
int sum = 0;
for(multimap<int,int>::iterator it=m.begin(); it!=m.end(); it++){
sum += (*it).first * (*it).second;
}
cout << sum << endl;
scanf("%d %d",&N,&M);
}
return 0;
}
HDU 3090
最新推荐文章于 2019-09-11 20:38:00 发布