链接

开两个队列 一个维护价格从大到小用来每次更新买油的价格 让每次都加满 如果当前价格比队列里的某价格低的话就更新 另开以优先队列维护价格由小到大

来更新此时用的油是什么油价的 并减掉

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL m[N],co[N],pr[N];
LL o[N];
int main()
{
int i,j,n,t,c;
cin>>t;
while(t--)
{
cin>>n>>c;
memset(o,,sizeof(o));
priority_queue <LL> q;
priority_queue<LL, vector<LL>, greater<LL> > p;
for(i = ; i <= n ;i++)
cin>>m[i]>>co[i]>>pr[i];
int flag = ;
int ts = ;
LL sum = ;
for(i = ; i <= n ;i++)
{
if(m[i]*co[i]>c){flag = ;break;}
int s = ;
while(!q.empty()&&pr[i]<=q.top())
{
sum-=o[q.top()]*q.top();
s+=o[q.top()];o[q.top()] = ;q.pop();
}
o[pr[i]] = s+c-ts;
if(o[pr[i]])
{
sum+=o[pr[i]]*pr[i];
q.push(pr[i]);
p.push(pr[i]);
}
LL ss = m[i]*co[i];
ts=c-ss;
while(ss)
{
int k = p.top();
if(o[k]<=ss)
{
ss-=o[k];o[k] = ;
}
else
{
o[k]-=ss;ss = ;
break;
}
p.pop();
}
}
if(!flag)
{
puts("Impossible");
continue;
}
while(!q.empty())
{
int k = q.top();
sum-=o[q.top()]*q.top();
q.pop();
}
cout<<sum<<endl;
}
return ;
}

zoj3699Dakar Rally的更多相关文章

  1. ZOJ 3699 Dakar Rally

    Dakar Rally Time Limit: 2 Seconds      Memory Limit: 65536 KB Description The Dakar Rally is an annu ...

  2. 【BZOJ-3832】Rally 拓扑序 + 线段树 (神思路题!)

    3832: [Poi2014]Rally Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 168  Solved:  ...

  3. URAL 1227 Rally Championship(树的直径)(无向图判环)

    1227. Rally Championship Time limit: 1.0 secondMemory limit: 64 MB A high-level international rally ...

  4. 如何解决Rally模板提示angular js加载错误

    [前言] Rally是一个开源测试工具,用于测试openstack各个组件的性能 在使用Rally测试完毕后,一般会生成测试报告,这点很重要.但是原生态的Rally报告模板angular js框架是从 ...

  5. AtCoder Grand Contest 002 D - Stamp Rally

    Description We have an undirected graph with N vertices and M edges. The vertices are numbered 1 thr ...

  6. BZOJ3832[Poi2014]Rally——权值线段树+拓扑排序

    题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...

  7. 【BZOJ3832】[POI2014]Rally(拓扑排序,动态规划)

    [BZOJ3832][POI2014]Rally(拓扑排序,动态规划) 题面 BZOJ,权限题 洛谷 题解 这题好强啊,感觉学了好多东西似的. 首先发现了一个图画的很好的博客,戳这里 然后我来补充一下 ...

  8. 3832: [Poi2014]Rally

    3832: [Poi2014]Rally 链接 分析: 首先可以考虑删除掉一个点后,计算最长路. 设$f[i]$表示从起点到i的最长路,$g[i]$表示从i出发到终点的最长路.那么经过一条边的最长路就 ...

  9. Stamp Rally

    Stamp Rally 最大值最小,可以二分,然后并查集看能不能到z个点 但是询问过多,并且发现每次二分要加入的点并不是所有的m条边 于是就考虑整体二分 并查集的处理是重点: 对于一般的dfs分治树, ...

随机推荐

  1. 成员函数指针 C++ FAQ LITE — Frequently Asked Questions

    http://www.sunistudio.com/cppfaq/pointers-to-members.html C++ FAQ LITE — Frequently Asked Questions ...

  2. web.xml中的ServletContextListener

    要想了解ServletContextListener,先看看web.xml中的<listener>配置. 一)web.xml中的内容载入顺序: 首先能够肯定的是,载入顺序与它们在 web. ...

  3. MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)<转>

    MVC 默认 Request 方式为 Post. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三&qu ...

  4. Part1-Redefining your data-access strategy 重新定义你的数据访问策略

    欢迎来到Entity Framework 4 In Action,EF是微软3.5 SP1推出的ORM工具,现在已经更新到4.0版本(...)本书能确保你in a  robust and model- ...

  5. keywords和favicon

    1.<meta name="keywords" content="xxx"> 曾经网站风靡关键词堆积,往往在首页上设置大量的关键词,以获取最大范围搜 ...

  6. WdatePicker.js的使用方法(转)

    WdatePicker.js的使用方法 博客分类: 其他   1. 跨无限级框架显示 无论你把日期控件放在哪里,你都不需要担心会被外层的iframe所遮挡进而影响客户体验,因为My97日期控件是可以跨 ...

  7. 添加数据成功之后,通过true、false决定是否跳转

    /** * 新增版本 * * @return */ public String AddVersionInfo() { // 快捷菜单 Integer code = Integer.parseInt(g ...

  8. HttpWebRequest以及HttpWebResponse

    上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...

  9. bzoj 2726 任务安排

    题目大意: 机器上有N个需要处理的任务,它们构成了一个序列 把这些任务分成若干批 从时刻0开始,这些任务被分批加工,第i个任务单独完成所需的时间是Ti 在每批任务开始前,机器需要启动时间S,而完成这批 ...

  10. AutoIT: 对数据库的访问,数据提取操作

    #include<array.au3> $conn= ObjCreate("ADODB.Connection") $RS= ObjCreate("ADODB. ...