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个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...
随机推荐
- 流程控制之while循环for循环
流程控制之while循环1.什么是循环 循环就是重复做某件事2.为什么要有循环 为了让计算机能够具备人重复做某件事的能力3.如何用循环 while语法: while 条件: code1 code2 c ...
- usb hub 设备流程图
在此处负责而来:http://blog.csdn.net/xuelin273/article/details/38646851 下面的转载于:http://blog.csdn.net/qianguo ...
- BFS:UVa1590-IP Networks (子网掩码相关知识)
IP Networks Alex is administrator of IP networks. His clients have a bunch of individual IP addresse ...
- Monkeyrunner 简介及其环境搭建
Monkeyrunner是通过坐标.控件ID和控件上的文字操作应用的界面元素,其测试用例是用python写的,这样就弥补了monkey只有简单命令无法执行复杂用例的缺陷.Monkeyrunner采用的 ...
- POJ 3281 网络流 拆点 Dining
题意: 有F种食物和D种饮料,每头牛有各自喜欢的食物和饮料,而且每种食物或者饮料只能给一头牛. 求最多能有多少头牛能同时得到它喜欢的食物或者饮料. 分析: 把每个牛拆点,中间连一条容量为1的边,保证一 ...
- js基础之javascript的存在形式和js代码块在页面中的存放位置和 CSS 对比
1.存在形式 文件 如: <script src='js/jc.js'></script> 前页面 <script type='text/javascript'>a ...
- FFT、NTT学习笔记
参考资料 picks miskcoo menci 胡小兔 unname 自为风月马前卒 上面是FFT的,学完了就来看NTT吧 原根 例题:luogu3803 fft优化后模板 #include < ...
- luogu2158 [SDOI2008]仪仗队 欧拉函数
点 $ (i,j) $ 会看不见当有 $ k|i $ 且 $ k|j$ 时. 然后就成了求欧拉函数了. #include <iostream> #include <cstring&g ...
- NumPy数值计算(1)
NumPy数值计算(1) 将列表转为NumPy中的array from __future__ import print_function from numpy import * import oper ...
- [python学习篇][廖雪峰][1]高级特性--创建生成器 方法1 a = (x for x in range(1,3))
创建一个生成器的方法: for x in range(1,10000000) ,先生成一个列表[1........9999999] 如果我们只想要后面的几个元素,会发现浪费很多空间.所以,如果列表元素 ...