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

排序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. GTK学习笔记之Linux下Gtk环境搭建

    下面介绍下Ubuntu 环境下具体的安装过程: 1.配置安装gcc/g++/gdb/make 等基本编程工具(必须装好) 刚装好的Ubuntu系统中已经有GCC了,但是这个GCC几乎什么文件都不能编译 ...

  2. 微信公众号授权登录,提示“redirect_uri 参数错误”

    做微信公众号开发授权登录的时候遇到的坑... 后台服务用node,index.js相关代码如下: const oauth = new OAuth(conf.appid, conf.appsecret) ...

  3. 2014-8-5 NOIP(雾)模拟赛

    皇帝的烦恼(二分答案) Description 经过多年的杀戮,秦皇终于统一了中国.为了抵御外来的侵略,他准备在国土边境安置n名将军.不幸的是这n名将军羽翼渐丰,开始展露他们的狼子野心了.他们拒绝述职 ...

  4. servlet连接mysql数据库和oracle数据库

    连接mysql数据库 package dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.P ...

  5. git小白的学习

    1.1 Git介绍 1.1.1 什么是Git Git是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理.Git 是 Linus Torvalds 为了帮助管理 Linux ...

  6. Junit使用总结

    对Junit的使用总结,后期会更新! 1.做自动单元测试用的,在方法前面加一个@Test(准备 一个测试用例),这是必须要加上的. 判定是成功还是失败. 最后是加一个断点,Assert.assertE ...

  7. net core 2.0 web api + Identity Server 4 + angular 5

    net core 2.0 web api + Identity Server 4 + angular 5前台使用angular 5, 后台是asp.net core 2.0 web api + ide ...

  8. 安装Jaspersoft Studio

    下载位置:http://community.jaspersoft.com/project/jaspersoft-studio/releases.

  9. 037 Sudoku Solver 解数独

    写一个程序通过填充空格来解决数独.空格用 '.' 表示. 详见:https://leetcode.com/problems/sudoku-solver/description/ class Solut ...

  10. (转)nginx应用总结(2)--突破高并发的性能优化

    原文:http://www.cnblogs.com/kevingrace/p/6094007.html 在日常的运维工作中,经常会用到nginx服务,也时常会碰到nginx因高并发导致的性能瓶颈问题. ...