B. Kefa and Company

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/580/problem/B

Description

Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.

Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!

Input

The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.

Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type misi(0 ≤ mi, si ≤ 109) — the amount of money and the friendship factor, respectively.

Output

Print the maximum total friendship factir that can be reached.

Sample Input

  1. 4 5
    75 5
    0 100
    150 20
    75 1

Sample Output

  1. 100

HINT

题意

给你n个人,告诉你每个人拥有多少钱,并且好感度是多少

如果在公司里面存在有一个人的钱大于等于他的话,这个人就会不开心

然后问你怎么安排,使得好感度最高

题解:

先排序,然后暴力

维护一个区间,这个区间都是可以选择的,至于怎么维护这个区间,可以尺取法,也可以而且搞

看自己咯

代码:

  1. //qscqesze
  2. #pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <ctime>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <set>
  10. #include <bitset>
  11. #include <vector>
  12. #include <sstream>
  13. #include <queue>
  14. #include <typeinfo>
  15. #include <fstream>
  16. #include <map>
  17. #include <stack>
  18. typedef long long ll;
  19. using namespace std;
  20. //freopen("D.in","r",stdin);
  21. //freopen("D.out","w",stdout);
  22. #define sspeed ios_base::ssecondnc_with_stdio(0);cin.tie(0)
  23. #define maxn 100006
  24. #define mod 1000000007
  25. #define eps 1e-9
  26. #define PI acos(-1)
  27. const double EP = 1E- ;
  28. int Num;
  29. //const int inf=0first7fffffff;
  30. const ll inf=;
  31. inline ll read()
  32. {
  33. ll x=,f=;char ch=getchar();
  34. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  35. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  36. return x*f;
  37. }
  38. //*************************************************************************************
  39.  
  40. ll sum[maxn];
  41. struct node
  42. {
  43. ll first,second;
  44. friend bool operator < (const node & x,const node & y)
  45. {
  46. return x.first < y.first;
  47. }
  48. };
  49. node A[maxn];
  50. int main()
  51. {
  52. int n=read();
  53. ll d=read();
  54. for(int i=;i<=n;i++)
  55. A[i].first = read(),A[i].second=read();
  56. sort(A+,A++n);
  57. for(int i=;i<=n;i++)
  58. sum[i]=sum[i-]+A[i].second;
  59. ll ans = ;
  60. ll ddd =;
  61. for(int i=;i<=n;i++)
  62. {
  63. int r = upper_bound(A+,A++n,node{A[i].first+d-1LL,ddd}) - A;
  64. ans = max(ans,sum[r-]-sum[i-]);
  65. }
  66. printf("%I64d\n",ans);
  67. }

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 per test 2 seconds memory limit per test 256 megabytes ...

  2. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

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

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

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

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

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

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

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

  9. Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】

    A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. 在QuickReport中实现多栏打印

      如果在Treport的DataSet属性中选定一个Table,那么QuickReport每次打印详细列表(BandType=rbDetail)属性的TQRBand时,系统会自动取出一个记录供打印, ...

  2. python Image PNG getpixel R/G/B/A

    # python Image PNG getpixel R/G/B/A# # 说明: # 本文主要是记录python中如何使用Image模块进行基本的图像R.G.B.A值得获取. # 为后续的rasp ...

  3. I.MX6 U-boot GPIO hacking

    /******************************************************************************* * I.MX6 U-boot GPIO ...

  4. LeetCode Lowest Common Ancestor of a Binary Search Tree (LCA最近公共祖先)

    题意: 给一棵二叉排序树,找p和q的LCA. 思路: 给的是BST(无相同节点),那么每个节点肯定大于左子树中的最大,小于右子树种的最小.根据这个特性,找LCA就简单多了. 分三种情况: (1)p和q ...

  5. erlang学习笔记之基础语法

    字符串是双引号,单引号的是atom元组: 下标从1开始 X = {'test1',2,3,4}. element(1,X). 配合模式匹配,可以给元素项命名,直接不用下标标记元素项 列表增删改查 增加 ...

  6. 如何使用UDP进行跨网段广播

    广播域首先我们来了解一下广播域的概念.广播域是网络中能接收任一台主机发出的广播帧的所有主机集合.也就是说,如果广播域内的其中一台主机发出一个广播帧,同一广播域内所有的其它主机都可以收到该广播帧.广播域 ...

  7. C# 中的 null

    原文 C# 中的 null C# 允许将 null 值赋给任意引用变量(不能把 null 赋给一个值变量).值为 null 的变量表明该变量不引用内存中的任何对象. 如下所示: Circle c = ...

  8. (Android Studio)ActionBar's Theme/Style [ActionBar主题风格修改]

    (1)默认theme代码如下: 运行结果: 视觉效果:ActionBar为Dark,背景为Light. (2)将theme改为Light: 运行结果: 视觉效果:ActionBar和背景都为Light ...

  9. Ildasm.exe(MSIL 反汇编程序)

    MSIL 反汇编程序是 MSIL 汇编程序 (Ilasm.exe) 的伙伴工具. Ildasm.exe 采用包含 Microsoft 中间语言 (MSIL) 代码的可迁移可执行 (PE) 文件,并创建 ...

  10. sys.argv[]基本用法

    #python 3.4.2 #windows系统下可以在CMD下执行 python test.py 第一参数 第2个参数 #空格分隔每个参数,sys.argv[]是用来获取命令行参数的 #引用必要的包 ...