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 ...
随机推荐
- python检测音频中的静音
#-*- coding: utf-8 -*- import os import wave from time import sleep import numpy as np SUCCESS = 0 F ...
- DB2中的NVL和NVL2函数
NVL函数是一个空值转换函数 NVL(表达式1,表达式2) 如果表达式1为空值,NVL返回值为表达式2的值,否则返回表达式1的值. 该函数的目的是把一个空值(null)转换成一个实际的值.其表达式的值 ...
- 【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation
problem 762. Prime Number of Set Bits in Binary Representation solution1: class Solution { public: i ...
- 最新 网易java校招面经 (含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易.京东.去哪儿等10家互联网公司的校招Offer,因为某些自身原因最终选择了网易.6.7月主要是做系统复习.项目复盘.LeetCode与牛客刷题 ...
- eNSP——静态路由的基本配置
原理: 静态路由是指用户或网络管理员手工配置的路由信息.当网络的拓扑结构或链路状态发生改变时,需要网络管理人员手工修改静态路由信息. 相比于动态路由协议,静态路由无需频繁地交换各自的路由表,配置简单, ...
- python中文编码 - python基础入门(5)
python到目前为止,一共有两个版本,分别是2.x和3.x版本,根据官方正式通知2020年停止对python更新和维护,距离今天还有110天左右,所以正在学习python的小伙伴应该暗中庆幸一波. ...
- python从hello world开始 - python基础入门(3)
万丈高楼平地起,编程亦如此.改变世界是结果,坚持努力学习改bug是过程,hello world是开始,所有语言均是如此. 一.使用pycharm创建第一个hello world 项目 1.Create ...
- [ReferenceError: __insane_exports is not defined] [monaco-editor@0.18.0] [vue] [typescript]
npm install monaco-editor@ 安装上面的命令,安装0.17.0版本.
- (十四)JDBC入门
目录 什么是JDBC 操作JDBC的步骤 DriverManager对象 数据库URL Connection对象 Statement对象 ResultSet对象 常用数据类型转换表 释放资源 SQL注 ...
- 题解 CF437C
基本思路---贪心 既然要求最小代价,当用一定顺序删除时代价一定最小,不难发现,每次都删去x,y中最小的,最后的总代价业一定最小! 因此就可以写出下面的简单的代码 代码 #include<ios ...