Codeforces Round #321 (Div. 2) Kefa and Company 二分
原题链接:http://codeforces.com/contest/580/problem/B
题意:
给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大m的差不超过d的情况下,s的和的最大值。
题解:
先排序,然后对于a[i],直接二分a[i].s+d的位置,然后维护一个前缀和,更新答案即可。
代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAX_N 100005
using namespace std; typedef long long ll; struct node{
public:
ll m,s;
bool operator<(const ll &x)const {
return m < x;
}
}; node a[MAX_N]; bool cmp(node x,node y) {
return x.m < y.m;
} int n;
ll d; ll sum[MAX_N]; int main() {
cin.sync_with_stdio(false);
cin >> n >> d;
for (int i = ; i < n; i++)cin >> a[i].m >> a[i].s;
sort(a, a + n,cmp);
sum[] = a[].s;
for (int i = ; i < n; i++)sum[i] = sum[i - ] + a[i].s;
ll ans = ;
for (int i = ; i < n; i++) {
int t = lower_bound(a, a + n, a[i].m + d) - a - ;
if (i == )ans = max(ans, sum[t]);
else
ans = max(ans, sum[t] - sum[i - ]);
}
cout<<ans<<endl;
return ;
}
Codeforces Round #321 (Div. 2) Kefa and Company 二分的更多相关文章
- Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa
原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...
- Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟
原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include< ...
- Codeforces Round #321 (Div. 2) Kefa and Park 深搜
原题链接: 题意: 给你一棵有根树,某些节点的权值是1,其他的是0,问你从根到叶子节点的权值和不超过m的路径有多少条. 题解: 直接dfs一下就好了. 代码: #include<iostream ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company 二分
B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/pr ...
- Codeforces Round #321 (Div. 2)-B. Kefa and Company,区间最大值!
->链接在此<- B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces Round #321 (Div. 2) B 二分+预处理
B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #321 (Div. 2) A, B, C, D, E
580A. Kefa and First Steps 题目链接: A. Kefa and First Steps 题意描述: 给出一个序列,求最长不降连续子序列多长? 解题思路: 水题,签到 代码: ...
- Codeforces Round #321 (Div. 2)
水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...
- 「日常训练」Kefa and Company(Codeforces Round #321 Div. 2 B)
题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...
随机推荐
- Anaconda的安装、使用以及与PyCharm的链接
初学Python的盆友们是否有这样的疑惑: 选择Python2还是Python3呢?(后者并不完全兼容前者) 听说两者可以同时安装,那怎么管理呢? Python那么丰富的第三方库,一个一个装太麻烦啦 ...
- poj-3009 curling2.0(搜索)
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26408 Accepted: 10546 Des ...
- Kubernetes(k8s)底层网络原理刨析
目录 1 典型的数据传输流程图 2 3种ip说明 3 Docker0网桥和flannel网络方案 4 Service和DNS 4.1 service 4.2 DNS 5 外部访问集群 5.1 外部访问 ...
- 使用css Flexbox实现垂直居中
CSS布局对我们来说一直是个噩梦,我们都认为flexbox是我们的救世主.是否真的如我们说说,还有待观察,但是flexbox确非常轻松的解决css长久一来比较难解决的居中问题.让我们来看看到底有多容易 ...
- MyBatis拦截器打印不带问号的完整sql语句方法
/* Preparing: SELECT * FROM tb_user WHERE id = ? AND user_name = ? 目标是打印:SELECT * FROM tb_user WHER ...
- VMware Workstation 14 PRO 下安装Ubuntu 16.04 LTS教程
一.准备好安装的VMware Workstation 14 PRO 1.VMware Workstation 14 PRO下载链接:http://rj.baidu.com/soft/detail/13 ...
- 聊聊、Nginx 参数合法性
我们接着上篇文章来讲讲 ngx_get_options 函数. 这个函数就在 nginx.c 文件中,我们来看看. 参数 argc,argv 我们在前面的文章中都已经提到了,在这里我们看 ngx_ge ...
- 刷题总结——小c找朋友(bzoj4264 集合hash)
题目: Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不同的)小Ci和j,如果其 ...
- jenkins使用xvfb插件构建虚拟化显示屏自动化测试
1.linux服务器安装xvfb,并启动 参考我的博客:http://www.cnblogs.com/lincj/p/5468505.html 或者网上搜索一下进行安装 2.jenkins安装xvfb ...
- java集合四种遍历方式
package conection; import java.util.Iterator;import java.util.LinkedList;import java.util.List; publ ...