Codeforces 853B Jury Meeting
题意
从城市1-n来的评审团到城市0商讨国家大事,离开和抵达的那一天不能讨论,飞机均当天抵达,给出所有飞机起飞抵达代价情况,问能否使所有评审员聚齐连续k天并返回,并求最小代价
思路
从前向后扫一遍,求每天的出发最小代价L[i],从后向前扫,求每天最小离开代价R[i]
从前向后扫一遍,每天的最小代价为L[i]+R[i+k+1]
将每天的默认大小设为1e12,因为最大代价不超过1e11,可以据此确定答案是否合法
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,k,d,f,t,c;
typedef long long ll;
const ll inf = 1e12;
const int maxn = 1e6+;
ll l[maxn], r[maxn], minn[maxn];
vector< pair<int, int> >to[maxn], back[maxn];
int main(){
scanf("%d %d %d",&n, &m, &k);
for(int i = ;i<m;i++){
scanf("%d %d %d %d",&d, &f,&t, &c);
if(t == ) to[d].push_back({f,c});
else back[d].push_back({t,c});
}
ll best = inf*n;
for(int i = ;i<maxn;i++) minn[i] = inf;
for(int i = ;i<maxn;i++){
for(pair<int,int> p : to[i]){
int dest = p.first, cost = p.second;
if(cost<minn[dest]) best-= (minn[dest]-cost), minn[dest] = cost;
}
l[i] = best;
}
best = inf*n;
for(int i = ;i<maxn;i++) minn[i] = inf;
for(int i = maxn-;i>=;i--){
for(pair<int,int> p : back[i]){
int dest = p.first, cost = p.second;
if(cost<minn[dest]) best-=(minn[dest]-cost), minn[dest] = cost;
}
r[i] = best;
}
ll ans = inf*n;
for(int i = ;i<maxn-k-;i++){
int rr = i+k+;
ans = min(ans,l[i]+r[rr]);
}
if(ans>=inf) return *printf("-1");
return *printf("%I64d",ans);
}
Codeforces 853B Jury Meeting的更多相关文章
- Codeforces 853B Jury Meeting (差分+前缀和)
<题目链接> 题目大意: 有$ n(n<=1e5)$个城市和一个首都(0号城市),现在每个城市有一个人,总共有$ m (m<=1e5)$次航班,每个航班要么从首都起飞,要么飞到 ...
- codeforces 853b//Jury Meeting// Codeforces Round #433 (Div. 1)
题意:几个人要去一个城市k天,现给出各航班的日期和花费,让这n个人能相会k天的最小花费? 用数组arr1[i]记录在第i天人到齐的最小花费.arr2[i]记录第i天之后才有人开始走的最小花费.然后取a ...
- Jury Meeting CodeForces - 854D
Jury Meeting CodeForces - 854D 思路:暴力枚举会议开始的那一天(只需用所有向0点飞的航班的那一天+1去枚举即可),并计算所有人此情况下去0点和从0点出来的最小花费. 具体 ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)
D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...
- Jury Meeting CodeForces - 854D (前缀和维护)
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...
- 【Codeforces Round #433 (Div. 1) B】Jury Meeting
[链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...
- codeforces round 433 D. Jury Meeting
题目大意: 输入n,m,k,分别代表城市的数量,城市编号1~n,航班的数量以及会议必须所有人员到会一起商议的天数,然后及时输入m行航班的信息,每一行输入d,f,t,c分别表示航班到站和始发的那一天(始 ...
- codeforces 782B The Meeting Place Cannot Be Changed (三分)
The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
随机推荐
- 【创业】2B创业历程
http://www.woshipm.com/chuangye/2800111.html http://www.woshipm.com/chuangye/2803240.html http://www ...
- vs2015配置link.exe环境变量
https://www.cnblogs.com/johnwii/p/4966086.html
- 【opencv】split
opencv-split Divides a multi-channel array into several single-channel arrays. code ,,,,,,,,,,,}; Ma ...
- 第五章 编码/加密——《跟我学Shiro》
转发地址:https://www.iteye.com/blog/jinnianshilongnian-2021439 目录贴:跟我学Shiro目录贴 在涉及到密码存储问题上,应该加密/生成密码摘要存储 ...
- 【ARTS】01_37_左耳听风-201900722~201900728
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- 报错: Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的权利字符串"
Code=3000 "未找到应用程序的“aps-environment”的权利字符串" 解决办法 push,即远程通知,教材的资料较少,想实践的话,只能每年花99美元买苹果开发者帐 ...
- React16+配置打包目录
在学习react的时候,肯定最终都要用脚手架,对比了手写配置webpack(比较费劲).generator-react-webpack(打不开官方文档……),最终还是选择了react官方的create ...
- java面试准备策略
我将结合网络教学视频,根据java以下几个特性进行学习. 平台无关性 GC 语言特性 面向对象 类库 异常处理
- php 云片国外短信实例
<?php namespace Ruifi\App; class SmsL { public function smsIcode($moblie,$sms_code,$intl_code){ h ...
- [转帖]CPU时间片
CPU时间片 https://www.cnblogs.com/xingzc/p/6077214.html CPU的时间片 CPU的利用率好CPU的 load average 是不一样的 Conntex ...