链接

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

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

 #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. 淘宝API学习之道:淘宝TOP之API接口接入教程

    作为一个中小型站点开发人员,淘宝API的开放大大缩短了站点的开发周期和运作效率.面对海量的数据.开发人员仅仅要细致阅读开发文档,熟悉对应的接口,就能够把数据导入自己的站点,这样就不必望洋兴叹了. 眼下 ...

  2. java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException

    java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException 遇到这样的问题 ...

  3. Ubuntu14.04 64bit下Caffe + CUDA 6.5安装详细步骤

    不多说,直接上干货! 笔者花了很长时间才装完,主要是cuda安装和opencv安装比较费劲,cuda找不到32位的安装包只好重装64位的ubuntu系统,opencv 也是尝试了很久才解决,这里建议用 ...

  4. 使用PowerShell 创建SharePoint 站点

    使用PowerShell 创建SharePoint 站点         在SharePoint开发中,你应该学会使用PowerShell管理SharePoint网站.SharePoint Manag ...

  5. [办公自动化]计算机突然断电,微软office文档(有asd文件)如何恢复?

    今天同事使用office软件时,突然故障.结果他忙了半天的word文档内容都找不见了. 经过查找,在其硬盘根目录找到了asd文档. 但是用当前版本的word和高版本的word软件都无法打开. 又查找了 ...

  6. 配置mahout

    构建Mahout要求系统事先安装 1)JDK 1.6 或更高版本 2)Maven 2.0.9 或 2.0.10 Mahout是Hadoop的一种高级应用.运行Mahout需要提前安装好Hadoop.H ...

  7. YTU 2811: 打鱼还是晒网

    2811: 打鱼还是晒网 时间限制: 1 Sec  内存限制: 128 MB 提交: 192  解决: 150 题目描述 中国有句俗话"三天打鱼,两天晒网".小王从2000年的1月 ...

  8. linux下的git安装及配置

    一.yum安装方式 1.安装 $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel $ yum -y ...

  9. Django Cache缓存系统介绍及Memcached使用

    在动态网站中,用户每次请求一个页面,服务器都会执行以下操作:查询数据库,渲染模板,执行业务逻辑,最后生成用户可查看的页面. 这会消耗大量的资源,当访问用户量非常大时,就要考虑这个问题了. 缓存就是为了 ...

  10. 小程序-demo:天气预报

    ylbtech-小程序-demo:天气预报 1.返回顶部 1.app.js //app.js App({ //系统事件 onLaunch: function () {//小程序初始化事件 var th ...