Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)
排序以后枚举尾部。尺取,头部单调,维护一下就好。
排序O(nlogn),枚举O(n)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define LOCAL
const int maxn = 1e5+;
struct Node
{
int m,s;
void IN(){ scanf("%d%d",&m,&s); }
bool operator < (const Node&rh) const {
return m < rh.m;
}
}nd[maxn]; ll ss[maxn]; int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n,d; scanf("%d%d",&n,&d);
for(int i = ; i <= n; i++){
nd[i].IN();
}
sort(nd+,nd++n);
for(int i = ; i <= n; i++){
ss[i] = ss[i-]+nd[i].s;
}
ll ans = ;
for(int i = ,j = ; i <= n; i++){
while(j<n && nd[j+].m - nd[i].m < d) j++;
ans = max(ans,ss[j]-ss[i-]);
}
printf("%I64d",ans);
return ;
}
Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)的更多相关文章
- 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 #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题
A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/58 ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...
- codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)
题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)
http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...
随机推荐
- MVC实用笔记
---------------------------- 渲染一个Action:@{Html.RenderAction("Rulelist", "AjaxReuqestD ...
- MS SQL读取JSON数据
前面有一篇<在SQL中直接把查询结果转换为JSON数据>https://www.cnblogs.com/insus/p/10905566.html,是把table转换为json. 现反过来 ...
- Git 分支管理 多人协作 远程仓库 补充
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了, 并且,远程仓库的默认名称是origin. 如果是本地仓库关联远程仓库 --- 要查看远程库的信息,用 ...
- 洛谷P3434 [POI2006]KRA-The Disks
P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...
- UIActionSheet的最后一项点击失效
在开发过程中,发现有时候UIActionSheet的最后一项点击失效,点最后一项的上半区域时有效,这是在特定情况下才会发生,这个场景就是试用了UITabBar的时候才有.解决办法: 在showView ...
- 一个模块对应一个Servlet对应一张表 BaseServlet抽取反射进行方法转发实现
- std::less
std::less 定义于头文件 <functional> template< class T >struct less; (C++14 前) template ...
- Django一些鲜为人知的操作
目录: - Django ORM执行原生SQL - QuerySet方法大全 一.Django ORM执行原生SQL # extra # 在QuerySet的基础上继续执行子语句 # extra(se ...
- 【bzoj1503】[NOI2004]郁闷的出纳员
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 13890 Solved: 5086[Submit][Stat ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...