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

排序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. Linux做脚本定时任务(定时清理日志)

    无论一些面试问题,还是实际应用,都会用到虚拟机的定时任务.现做定时清理日志日志做一总结. 1.查看/etc/crontab文件. linux 系统则是由 cron (crond) 这个系统服务来控制的 ...

  2. 大白话5分钟带你走进人工智能-第二十六节决策树系列之Cart回归树及其参数(5)

                                                    第二十六节决策树系列之Cart回归树及其参数(5) 上一节我们讲了不同的决策树对应的计算纯度的计算方法, ...

  3. [Lintcode]Inorder Successor in Binary Search Tree(DFS)

    题意 略 分析 1.首先要了解到BST的中序遍历是递增序列 2.我们用一个临时节点tmp储存p的中序遍历的下一个节点,如果p->right不存在,那么tmp就是从root到p的路径中大于p-&g ...

  4. 洛谷P2292 [HNOI2004]L语言

    传送门 建好trie树 当$dp[j]==1$当且仅当存在$dp[k]=1$且$T[k+1,j]==word[i]$ 然后乱搞就行了 //minamoto #include<iostream&g ...

  5. [Xcode 实际操作]七、文件与数据-(5 )复制、移动、删除文件和删除文件夹

    目录:[Swift]Xcode实际操作 本文将演示如何复制.移动和删除文件. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit class ...

  6. IntelliJ IDEA 安装golang 插件

    作者的机器为mac OS 用户首先需要在自己的个人机器上安装好 golang 的环境,详细可以参考  hyperledger fabric 1.0.5 分布式部署 (一)安装 golang 的部分. ...

  7. PJzhang:谷歌在中国大陆可以使用的部分服务

    猫宁!!! 参考链接:https://lusongsong.com/reed/170.html https://www.williamlong.info/archives/2124.html http ...

  8. Java进程占用内存过高,排查解决方法

    最近收到邮件报警,说内存使作率达到84%.如下图: 解决方法: A:可能是代码原因导致的问题: 1.使用命令:top 查看当前进程的状态 2.从上图可以看到PID:916的java进程占用内存较大.定 ...

  9. SpringSecurity为项目加入权限控制

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  10. GDPR(Cookie处理)

    GDPR(Cookie处理) https://www.cnblogs.com/GuZhenYin/p/9154447.html 前言 时间一晃 ASP.NET Core已经迭代到2.1版本了. 迫不及 ...