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+5; 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 LOCALfreopen("in.txt","r",stdin); #endifint n,d; scanf("%d%d",&n,&d);for(int i = 1; i <= n; i++){nd[i].IN();}sort(nd+1,nd+1+n);for(int i = 1; i <= n; i++){ss[i] = ss[i-1]+nd[i].s;}ll ans = 0;for(int i = 1,j = 1; i <= n; i++){while(j<n && nd[j+1].m - nd[i].m < d) j++;ans = max(ans,ss[j]-ss[i-1]);}printf("%I64d",ans);return 0; }
转载于:https://www.cnblogs.com/jerryRey/p/4831291.html
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) 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) D Kefa and Dishes(dp)
用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...
- Codeforces Round #588 (Div. 2) F. Konrad and Company Evaluation 图论 + 建反图 好题
传送门 文章目录 题意: 思路: 题意: 给你一张nnn个点mmm条边的图,其中每个点iii初始编号为iii,边是有向的,方向为从编号大的指向编号小的.定义一个贡献为存在某三个点a,b,ca,b,ca ...
- Codeforces Round #321 (Div. 2)
水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...
- Codeforces Round #321 (Div. 2) Kefa and Company 二分
原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大 ...
- Codeforces Round #321 (Div. 2) E
终于补好了. 题目链接: http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 sec ...
- codeforces Round #675 (Div. 2) 1422C Bargain
题目链接 题目翻译: 有时候想在讲价上达成一致不是一件容易的事.现在Sasha和Vova就没法达成一致:Sasha出了一个尽可能高的价格,然后Vova想要从中去除尽可能多的数字.说得更详细一些,Sas ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
最新文章
- 10搜索文件内容搜不出_百度搜索广告太多?内容太杂?可能你们缺少这10个神器网站...
- git commit —amend_Git之修改commit记录
- 【聊透SpringMVC】java找不到指定文件
- python装饰器实例-python 装饰器(三):装饰器实例(一)
- 漫谈架构师之路的修仙之法
- matlab hist函数_算法工匠MATLAB专训营:Matlab绘图,小试牛刀
- Python中OpenCV2. VS. CV1
- mongodb 数组添加_NoSQL之MongoDB——简介
- Debian卸载iceweasel
- 社会生存的75条忠告----胜读十年书【转】
- 构造java_Java构造方法
- Pdftk - The PDF Toolkit
- 【渝粤教育】国家开放大学2018年春季 8612-22T传染病护理学 参考试题
- zabbix3.4+grafana5.0.1数据可视化
- paip.表格化CSV输出
- 自由软件之父Richard Stallman及其思想
- 阿里云服务器桌面版配置
- Microsoft SQL Server 2008R2企业版64位(带密钥)
- Windows 下设置开机启动项
- EAS F7 左树右表
热门文章
- VC控件 Edit Control
- ACCESS在哪输入SQL语句
- java乒乓_Java -- 乒乓球 乒乓弹球游戏
- oracle 增加ora容量_案例:Oracle报错ORA-01144 详解数据文件大小32GB的限制的原因
- 容器的访问元素的成员函数(front,back,下标和at)返回的都是引用
- 计算机网络(第七版)谢希仁编著 第一章习题详解1-28
- [BUUCTF-pwn]——jarvisoj_level2_x64
- 学习记录-class与namespace的区别
- oracle with check option 的作用
- Struts2返回JSON对象的方法总结