码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2431

时间:2019-02-25 21:56:03      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:ons   cst   turn   code   algo   def   push   http   const   

POJ  2431

http://poj.org/problem?id=2431

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector>
//const int maxn = 1e5+5;
#define ll long long
#define MAX INT_MAX
#define FOR(i,a,b) for( int i = a;i <= b;++i)
using namespace std;
int N,L,P,ans1,ans,need;
struct node
{
    int dis,fuel;
}v[11000];
bool cmp(node a,node b)
{
    return a.dis<b.dis;
}
int main()
{
    priority_queue<int>pque;
   cin>>N;
   FOR(i,1,N)
   {
       cin>>v[i].dis>>v[i].fuel;
   }
   cin>>L>>P;
   FOR(i,1,N)
   {
       v[i].dis=L-v[i].dis;
   }
   sort(v+1,v+1+N,cmp);
   
   int weizhi=0,youliang=P;
   v[N+1].dis=L;
   v[N+1].fuel=0;
   FOR(i,1,N+1)
   {
      need=v[i].dis-weizhi;
      while(youliang<need)
      {
          if(pque.empty()==1)
          {
              cout<<"-1";
              return 0;
          }
          youliang+=pque.top();
          pque.pop();
          ans++;
      }
      pque.push(v[i].fuel);
      youliang-=need;
      weizhi=v[i].dis;
   }
   cout<<ans<<endl;

}

 

POJ 2431

标签:ons   cst   turn   code   algo   def   push   http   const   

原文地址:https://www.cnblogs.com/jrfr/p/10433486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!