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 ...
随机推荐
- tk.mybatis 报错:tk.mybatis.mapper.MapperException: tk.mybatis.mapper.MapperException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiLogMapper ...
- LeetCode_118. Pascal's Triangle
118. Pascal's Triangle Easy Given a non-negative integer numRows, generate the first numRows of Pasc ...
- LeetCode_108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree Easy Given an array where elements are sorted in asc ...
- JBPM使用
jbpm+mysql5.7 https://blog.csdn.net/tyn243222791/article/details/79033555
- hadoop在windows上的配置文件
core-site.xml <configuration> <property> <name>hadoop.tmp.dir</name> <val ...
- ELK之elasticsearch删除索引
参考文档:https://www.cnblogs.com/Dev0ps/p/9493576.html elasticsearch使用时间久了会产生大量索引占用磁盘空间,可以删除索引来释放 查看当前所有 ...
- netstat -anp/ss -t里的Send-Q和Recv-Q含义
Send-Q 对方没有收到的数据或者说没有Ack的,还在本地缓冲区 Recv-Q 数据已经在本地接收缓冲区,但是还没有recv() The count of bytes not copied by t ...
- 【c# 学习笔记】使用virtual和override关键字实现方法重写
只有基类成员声明为virtual或abstract时,才能被派生类重写:而如果子类想改变虚方法的实现行为,则必须使用override关键字. public class Animal { private ...
- 使用Rabbit MQ消息队列
使用Rabbit MQ消息队列 综合概述 消息队列 消息队列就是一个消息的链表,可以把消息看作一个记录,具有特定的格式以及特定的优先级.对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息 ...
- 1.Cloudera Manager安装
安装环境采用2台虚拟机进行,一台master, 一台slave1 先安装好centos 6.5 两台,并设置静态ip 怎么安装可以参考地址:https://jingyan.baidu.com/arti ...