CodeForces822C【贪心】
来源:互联网 发布:赫鲁晓夫 知乎 编辑:程序博客网 时间:2024/06/09 21:17
思路:
对于每个位置,维护其左边以区间长度为 len 的最小值。
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int N = 2e5 + 10;struct asd{ int Left, Right; LL cos;}q[N];int n, x;vector<asd>a[N], b[N];LL num[N];int main(){ scanf("%d%d",&n,&x); for(int i=1;i<=n;i++){ scanf("%d%d%I64d",&q[i].Left, &q[i].Right, &q[i].cos); a[q[i].Left].push_back(q[i]); b[q[i].Right].push_back(q[i]); } for(int i=1;i<=200000;i++) num[i] = 1e18; LL ans = 1e18; for(int i=1;i<=200000;i++){ int sz = a[i].size(); int len; for(int j=0;j<sz;j++){ len = a[i][j].Right - a[i][j].Left + 1; if(x > len){ len = x - len; if(num[len] != 1e18) ans = min(ans, num[len] + a[i][j].cos); } } sz = b[i].size(); for(int j=0;j<sz;j++){ len = b[i][j].Right - b[i][j].Left + 1; num[len] = min(num[len], b[i][j].cos); } } if(ans == 1e18) puts("-1"); else printf("%I64d\n", ans); return 0;}
阅读全文
0 0
- CodeForces822C【贪心】
- codeforces822C(排序+贪心)
- codeforces822c+codeforces612d
- 贪心!
- 贪心~
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 2017年7月-占位
- 2017年7月30日-占位
- 关于排序
- java学习初探1
- 2017年7月-占位3
- CodeForces822C【贪心】
- HDU
- POJ2082 Terrible Sets(单调栈)
- 安装 magenta 失败:rtmidi
- Python3中的PyMongo如何使用?
- JDBC
- springmvc学习笔记3
- Web跨域分析与解决
- http问题