把卡车油用完,然后把 到终点距离大于车到终点距离的全部油站的油 按 油的多少 推进优先队列,然后 取出顶端,车到终点距离减掉这部分油,再进行添加 经过的油站,取最多的油,继续走,,,知道l<=0 或者 队列为空 -
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
struct node
{
int fule;
int dis;
bool operator < (const node & b) const
{
return fule<b.fule;
}
};
node tm[10000+5];
int cmp(node a,node b)
{
return a.dis>b.dis;
}
priority_queue <node> qq;
int main()
{
int l,p,n;
scanf("%d",&n);int i;
for (i=1;i<=n;i++)
{
scanf("%d%d",&tm[i].dis,&tm[i].fule);
}
scanf("%d%d",&l,&p);
sort(tm+1,tm+1+n,cmp);
if (p>=l) {printf("0\n");return 0;}
int index=1;
l-=p;
int cun=0;
while(l<=tm[index].dis)
{
qq.push(tm[index]);
index++;
}
while (l>0&&!qq.empty())
{
node tmp=qq.top();
qq.pop();
cun++;
l-=tmp.fule;
while(l<=tm[index].dis&&index<=n)
{
qq.push(tm[index]);
index++;
}
}
if (l<=0) printf("%d\n",cun);
else
printf("-1\n");
return 0;
}