POJ 2431 Expedition
没油瞬移回去加
为了少次数每次尽可能多加
#include <iostream>
#include <queue>
using namespace std;
const int MAXL=1000111;
int N;
int L, Now;
int Val[MAXL];
int Ans=0;
bool Flag=true;
priority_queue<int> PQ;
int main(){
ios_base::sync_with_stdio(false);
cin >> N;
for(int i=1, d, v;i<=N;++i){
cin >> d >> v;
Val[d]+=v;
}
cin >> L >> Now;
for(int i=L-1;i>=1;--i){
if(Val[i]>0) PQ.push(Val[i]);
--Now;
if(Now==0){
if(PQ.empty()){
Flag=false;
break;
}
Now+=PQ.top();PQ.pop();
++Ans;
}
}
if(Flag) cout << Ans << endl;
else cout << "-1" << endl;
return 0;
}