原题链接: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 二分的更多相关文章

  1. Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa

    原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...

  2. Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟

    原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include< ...

  3. Codeforces Round #321 (Div. 2) Kefa and Park 深搜

    原题链接: 题意: 给你一棵有根树,某些节点的权值是1,其他的是0,问你从根到叶子节点的权值和不超过m的路径有多少条. 题解: 直接dfs一下就好了. 代码: #include<iostream ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #321 (Div. 2) B 二分+预处理

    B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #321 (Div. 2) A, B, C, D, E

    580A. Kefa and First Steps 题目链接: A. Kefa and First Steps 题意描述: 给出一个序列,求最长不降连续子序列多长? 解题思路: 水题,签到 代码: ...

  8. Codeforces Round #321 (Div. 2)

    水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...

  9. 「日常训练」Kefa and Company(Codeforces Round #321 Div. 2 B)

    题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...

随机推荐

  1. python爬虫基础10-selenium大全4/8-Webelement

    Selenium笔记(4)Webelement 本文集链接:https://www.jianshu.com/nb/25338984 这是通过find方法找到的页面元素,此对象提供了多种方法,让我们可以 ...

  2. 中国电信物联网平台入门学习笔记7:NB-IOT信号如何检测

    NB-IOT设备会因为信号的原因,数据发不出.但数据发不出的原因有很多,这么排除是NB-IOT信号的问题呢?那就需要NB-IOT信号检测装置. 网上的信号检测设备 作为一个常年蜗居在实验室的穷屌丝而言 ...

  3. NO_PUBKEY

    * 现象:$ sudo apt-get update时警告如下: W: GPG error: http://ppa.launchpad.net precise Release: The followi ...

  4. Linux对大容量硬盘分区

    随着单块硬盘容量的增大和硬盘价格的下降,2TB的磁盘使用将很快会普及,由于传统的MBR方式存储分区表的方 式缺陷,将可能导致很多分区工具不能正确地读取大于2TB容量的硬盘而无法正常分区大容量硬盘.其实 ...

  5. UVa 11795 状压DP Mega Man's Mission

    kill[S]表示消灭机器人的集合为S,剩下的所能杀死的机器人集合. 设d(S)表示杀死机器人集合为S的方法数,答案为d((1<<n) - 1). d(S)可以由d(S')转移过来,其中S ...

  6. 如何从Maven中央存储库下载?

    根据 Apache Maven说明: 下载时由项目的 pom.xml 文件的依赖来决定,目前不在本地存储库触发(当中央存储库包含了一个更新).默认情况下,Maven将从中央存储库下载. 在Maven中 ...

  7. luogu1972 [SDOI2009]HH的项链

    莫队裸题还不带修改 #include <algorithm> #include <iostream> #include <cstdio> #include < ...

  8. react技术栈实践(1)

    本文来自网易云社区 作者:汪洋 背景 最近开发一个全新AB测试平台,思考了下正好可以使用react技术开发. 实践前技术准备 首先遇到一个概念,redux.这货还真不好理解,大体的理解:Store包含 ...

  9. ios开发讲解之anchorPoint和position详解

    引言 相信初接触到CALayer的人都会遇到以下几个问题:  为什么修改anchorPoint会移动layer的位置? CALayer的position点是哪一点呢? anchorPoint与posi ...

  10. 爬虫Scrapy框架-2爬取网站视频详情

     爬取视频详情:http://www.id97.com/ 创建环境: movie.py 爬虫文件的设置: # -*- coding: utf-8 -*- import scrapy from movi ...