zoj3699Dakar Rally
开两个队列 一个维护价格从大到小用来每次更新买油的价格 让每次都加满 如果当前价格比队列里的某价格低的话就更新 另开以优先队列维护价格由小到大
来更新此时用的油是什么油价的 并减掉
#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的更多相关文章
- ZOJ 3699 Dakar Rally
Dakar Rally Time Limit: 2 Seconds Memory Limit: 65536 KB Description The Dakar Rally is an annu ...
- 【BZOJ-3832】Rally 拓扑序 + 线段树 (神思路题!)
3832: [Poi2014]Rally Time Limit: 20 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 168 Solved: ...
- URAL 1227 Rally Championship(树的直径)(无向图判环)
1227. Rally Championship Time limit: 1.0 secondMemory limit: 64 MB A high-level international rally ...
- 如何解决Rally模板提示angular js加载错误
[前言] Rally是一个开源测试工具,用于测试openstack各个组件的性能 在使用Rally测试完毕后,一般会生成测试报告,这点很重要.但是原生态的Rally报告模板angular js框架是从 ...
- 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 ...
- BZOJ3832[Poi2014]Rally——权值线段树+拓扑排序
题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...
- 【BZOJ3832】[POI2014]Rally(拓扑排序,动态规划)
[BZOJ3832][POI2014]Rally(拓扑排序,动态规划) 题面 BZOJ,权限题 洛谷 题解 这题好强啊,感觉学了好多东西似的. 首先发现了一个图画的很好的博客,戳这里 然后我来补充一下 ...
- 3832: [Poi2014]Rally
3832: [Poi2014]Rally 链接 分析: 首先可以考虑删除掉一个点后,计算最长路. 设$f[i]$表示从起点到i的最长路,$g[i]$表示从i出发到终点的最长路.那么经过一条边的最长路就 ...
- Stamp Rally
Stamp Rally 最大值最小,可以二分,然后并查集看能不能到z个点 但是询问过多,并且发现每次二分要加入的点并不是所有的m条边 于是就考虑整体二分 并查集的处理是重点: 对于一般的dfs分治树, ...
随机推荐
- Malformed or corrupted AST file: 'Unable to load module "...
Malformed or corrupted AST file: 'Unable to load module "/Users/topbar/Library/Developer/Xcode/ ...
- 机器学习和深度学习笔记(Matlab语言实现)
不多说,直接上干货! 这里,对于想用matlab语言来做的朋友,强烈推荐 http://www.cnblogs.com/tornadomeet/
- adb端口被占用情况下如何杀掉进程
1.CMD命令窗口输入:adb nodaemon server .然后就会提示你哪个端口被占用了. 2.输入netstat -ano | findstr "5037" .然后会弹出 ...
- Java对象的创建过程
//TODO https://www.cnblogs.com/chenyangyao/p/5296807.html
- Win10快捷键总结
微软自发布Windows10以来,大部分的电脑系统都已更新.除了大量的新功能和界面改进,Windows 10中同样包含了一批新的键盘快捷键.熟练使用这些快捷键可以大大提高操作效率,很实用,推荐大家收藏 ...
- GrideView(二)---删除功能
情景一. 没有外键关联, 操作:在数据源中将删除选项选中--- GrideView 中的删除 选项选中 即可情景二. 有外键关联 *RowDeleting 行删除前触发 *RowDeleted 行删除 ...
- HDU3001 Travelling —— 状压DP(三进制)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3001 Travelling Time Limit: 6000/3000 MS (Java/ ...
- 调整多个控件的dock的顺序
https://stackoverflow.com/questions/2607508/how-to-control-docking-order-in-winforms Go to View -> ...
- Iphone 启动图的尺寸
APP图标设置 - 取Images.xcassets中的AppIcon, 图标尺寸 29pt * 2x => 58 * 5829pt * 3x => 87 * 8740pt * 2x =& ...
- java的内部类解析
内部类分为四种: 成员内部类.类方法与普通方法同级: 局部内部类.类方法内部,局部内部类有构造器,通过构造器把外部的变量传入局部内部类再使用是完全可以的 匿名内部类.匿名内部类是唯一没有构造器的类,和 ...