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个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...
随机推荐
- GoF23种设计模式之行为型模式之备忘录模式
一.概述 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象的外部保存这个状态.以便以后可以将该对象恢复到原先保存的状态. 二.适用性 1.当需要保存一个对象在某个时刻的状态( ...
- Hessian知识学习总结(二)——Hessian的helloworld
一.下载Hessian 可在hessian官网http://hessian.caucho.com/ 或者http://download.csdn.net/detail/wodediqizhang/95 ...
- python中文件操作的六种模式及对文件某一行进行修改的方法
一.python中文件操作的六种模式分为:r,w,a,r+,w+,a+ r叫做只读模式,只可以读取,不可以写入 w叫做写入模式,只可以写入,不可以读取 a叫做追加写入模式,只可以在末尾追加内容,不可以 ...
- SQL语句小练习
一.创建如下表结构(t_book) Id 主键 自增一 bookName 可变长 20 Price 小数 Author 可变长20 bookTypeId 图书类 ...
- statistics-skewed data
参考文献: http://www.statisticshowto.com/skewed-distribution/ left/negatively-skewed distributions : box ...
- SQL前后端分页
/class Page<T> package com.neusoft.bean; import java.util.List; public class Page<T> { p ...
- vagrant 安装ubuntu12.04 64 bit
1 下载用于ubuntu 12.04 用于vagrant的镜像,虚拟机是virtualbox $ wget http://files.vagrantup.com/precise64.box jb@e3 ...
- poj2195 bfs+最小权匹配
题意:给个矩阵,矩阵里有一些人和房子(人数和房子数相等),一个人只进一个房子(可以路过房子而不进),每走一步花费1美金,求所有人都进入房子的最小花费,这是典型的二分图带权匹配问题. 这题就是建图有点麻 ...
- MyInt的简单实现
#include <iostream> using namespace std; class CMyInt{ private: int value; public: CMyInt(int ...
- ranorex前一步的操作结果后一步如何调用
if (!TestSuite.Current.Parameters.ContainsKey("Password"))TestSuite.Current.Parameters.Ad ...