【Codeforces Round #433 (Div. 1) B】Jury Meeting
【链接】h在这里写链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std; const int N = 1e6; int n, m, k;
vector <pair <int, int > > in[N + 10], out[N + 10];
long long f1[N + 10], f2[N + 10];
int num1[N + 10], num2[N + 10];
int mi[N + 10], MI[N + 10]; int main() {
ios::sync_with_stdio(0), cin.tie(0); cin >> n >> m >> k;
for (int i = 1; i <= m; i++) {
int d, f, t, c;
cin >> d >> f >> t >> c;
if (t == 0)
in[d].push_back(make_pair(f, c));
else {
//f == 0
out[d].push_back(make_pair(t, c));
}
} for (int i = 1; i <= N; i++) {
num1[i] = num1[i - 1];
f1[i] = f1[i - 1];
for (int j = 0; j <= (int)in[i].size() - 1; j++) {
int from = in[i][j].first, cost = in[i][j].second;
if (mi[from] == 0) {
mi[from] = cost;
num1[i]++;
f1[i] += cost;
}
else {
if (mi[from] > cost) {
f1[i] -= (mi[from] - cost);
mi[from] = cost;
}
}
}
} for (int i = N; i >= 1; i--) {
f2[i] = f2[i + 1];
num2[i] = num2[i + 1];
for (int j = 0; j <= (int)out[i].size() - 1; j++){
int to = out[i][j].first; int cost = out[i][j].second;
if (MI[to] == 0) {
MI[to] = cost;
f2[i] += cost;
num2[i]++;
}
else {
if (MI[to] > cost) {
f2[i] -= (MI[to] - cost);
MI[to] = cost;
}
}
}
} long long ans = -1;
for (int i = 1; i + k +1 <= N; i++)
if (num1[i]==n){
if (num2[i + k + 1] == n) {
long long temp = f1[i] + f2[i + k + 1];
if (ans == -1) {
ans = temp;
}
else
ans = min(ans, temp);
}
}
cout << ans << endl;
return 0;
}
【Codeforces Round #433 (Div. 1) B】Jury Meeting的更多相关文章
- 【Codeforces Round #433 (Div. 2) C】Planning
[链接]h在这里写链接 [题意] 让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样. 且ti>=i必须成立. [题解] 分解一下成为∑ti*gi ...
- 【Codeforces Round #433 (Div. 2) B】Maxim Buys an Apartment
[链接]h在这里写链接 [题意] 你有n个位置,然后其中有k个地方是已经被人占据了的. 一个"好的位置"的定义是指,这个位置相邻的地方其中至少有一个被人占据了. k个被人占据的位置 ...
- 【Codeforces Round #433 (Div. 2) A】Fraction
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举分子从高到低就好. 这样得到的一定是最大的. (可以约分没错,但是约分过后和就不是n了,所以不会有错的) [错的次数] 0 [反思] 在这 ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(二维线段树)
[链接]我是链接 [题意] 接上一篇文章 [题解] 接(点我进入)上一篇文章. 这里讲一种用类似二维线段树的方法求矩形区域内点的个数的方法. 我们可以把n个正方形用n棵线段树来维护. 第i棵线段树维护 ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)
[链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...
- 【Codeforces Round #424 (Div. 2) C】Jury Marks
[Link]:http://codeforces.com/contest/831/problem/C [Description] 有一个人参加一个比赛; 他一开始有一个初始分数x; 有k个评委要依次对 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
随机推荐
- [React] Write Compound Components
Compound component gives more rendering control to the user. The functionality of the component stay ...
- Nginx+tomcat+ssl免费证书配置
0.说明 本文说描写叙述的方式是用nginx的443重定向到tomcat的8443,nginx的80port重定到tomcat的8080: 乱入:个人标记:caicongyang 1.nginx安装 ...
- [转]C语言预处理命令详解
转载:https://www.cnblogs.com/clover-toeic/p/3851102.html 一 前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的 ...
- [欧拉回路] poj 1386 Play on Words
题目链接: http://poj.org/problem?id=1386 Play on Words Time Limit: 1000MS Memory Limit: 10000K Total S ...
- FocusChange-焦点变化监听事件
想要监听一个控件的焦点变化情况,发现了一个 view.setOnFocusChangeListener(new OnFocusChangeListener() { ...... } 现在写一个小dem ...
- HDU 2564 饭卡
饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- css3 transform:scale(x)实现字体的缩放:
css3 transform:scale(x)字体的缩放: transform:scale(x),针对于整体的缩放,缩放的整体包括宽,高,背景.这自然对于内联元素就无法使用此属性,最好使用无属性的sp ...
- Django模型三
关联对象操作及多表查询 关联表的数据操作: 一对多: 正向:如果一个模型有外键字段,通过这个模型对外键进行操作叫做正向. 更新: 通过属性赋值 In [1]: from teacher.models ...
- iframe自适应高度解决方法 .
<div id="leftBar"> <iframe name="tag" src="_iframe.html" styl ...
- Method and apparatus for transitioning between instruction sets in a processor
A data processor (104) is described. The data processor (104) is capable of decoding and executing a ...