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分治树, ...
随机推荐
- HDU4763 Theme Section 【KMP】
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- C语言 字符串操作 笔记
/* C语言字符串的操作笔记 使用代码和注释结合方式记录 */ # include <stdio.h> # include <string.h> int main(void) ...
- mysql最新版中文参考手册在线浏览
MySQL是最流行的开放源码SQL数据库管理系统,具有快速.可靠和易于使用的特点.同时MySQL也是一种关联数据库管理系统,具有很高的响应速度和灵活性.又因为mysql拥有良好的连通性.速度和安全性, ...
- 朴素的标题:MVC中权限管理实践
基于MVC的web项目最好的权限控制方式我认为是对Action的控制,实现思路记录于此,权限管理分成两个部分授权.认证. 一.授权 1.读取当前项目中的所有需要控制的Action /// <su ...
- sharpdevelop 调整代码字体显示大小
SharpDevelop中使用ctrl+鼠标滚轮可以调整代码的字体显示大小
- HTML5你必须知道的28个新特性
1. 新的Doctype 尽管使用<!DOCTYPE html>,即使浏览器不懂这句话也会按照标准模式去渲染 2. Figure元素 用<figure>和<figcapt ...
- click event not triggered on bootstrap modal
I am trying to catch the click event when save changes is pushed. For some reason i can't catch the ...
- 内存溢出-jvisualvm排查问题
先来一段能够内存溢出的程序 public static void main(String[] args) { List<Object> list = new ArrayList<&g ...
- 并不对劲的loj2134:uoj132:p2304:[NOI2015]小园丁与老司机
题目大意 给出平面直角坐标系中\(n\)(\(n\leq5*10^4\))个点,第\(i\)个点的坐标是\(x_i,y_i(|x_i|\leq10^9,1\leq y_i\leq10^9)\),只有朝 ...
- 【HAOI 2006】 受欢迎的牛
[题目链接] 点击打开链接 [算法] 先用tarjan缩点,然后找出度为零的点,即可 [代码] #include<bits/stdc++.h> using namespace std; # ...