排序以后枚举尾部。尺取,头部单调,维护一下就好。

排序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 (尺取)的更多相关文章

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

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

  3. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

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

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

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

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

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

  9. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

随机推荐

  1. EF中外键重命名,打破原先的约束规则

    本人建议玩code frist的人多用用System.ComponentModel.DataAnnotations和System.ComponentModel.DataAnnotations.Sche ...

  2. 原生js实现一个侧滑删除取消组件(item slide)

    组件,本质上是解决某个问题封装的类,在此记录原生js实现侧滑删除 先上效果图 实现思路 1. 确定渲染的数据结构 2. 思考划分布局,总的有两个主要的模块:内容区域和按钮区域 2.1 内容区域保持宽度 ...

  3. react中循环节点的方式以及图片引用的方式

    import React from 'react' import img from '../public/img/001.jpg' // 此时img是一个变量,在下面直接使用该变量即可引入该图片 cl ...

  4. [NOIP2008] 传球游戏

    1011. [NOIP2008] 传球游戏 http://cogs.pro/cogs/problem/problem.php?pid=1011 ★   输入文件:ballg.in   输出文件:bal ...

  5. 洛谷P4052 [JSOI2007]文本生成器(AC自动机)

    传送门 好像这题的确只能用AC自动机做了……Aufun大佬太强啦 正着难我们反着做,用总共单词个数减去没有一个单词都不包含的 然后考虑怎么处理一个单词都不包含的,就是跑不到单词的结尾节点 定义$f[i ...

  6. HTML5math标签

    HTML5 MathML 一.HTML5 可以在文档中使用 MathML 元素,对应的标签是 <math>...</math> . MathML 是数学标记语言,是一种基于XM ...

  7. java基础第七篇之接口

    1.什么是接口: * 接口是方法的集合,而且接口中的方法全是抽象的 * 你可以把接口看成一个特殊的"抽象类",接口中的方法全是抽象的 * * * 2.java中怎么定义接口: * ...

  8. Theme Section

    题目链接 #include <cstdio> #include <iostream> #include <cstring> using namespace std; ...

  9. JS高级学习历程-5

    [闭包] 定义:闭包就是一个函数 条件:一个函数去嵌套另外一个函数,里边的函数就是闭包 function  f1(){ function f2(){ } } 特点:闭包函数有权访问父级环境的变量信息.

  10. 程序员/开发人员的真实生活 (Gif 多图)

    往工作环境上传东西的时候: 没保存,就关了 IDE 的时候: 凌晨三点调代码的时候: 正则表达式返回了了预期结果的时候: 当老板告诉我,我那一直负责的模块失效了的时候: 刚修复了Bug,我给老板演示的 ...