题目链接:https://vjudge.net/problem/Gym-102569B

题意:数轴上有N个点,从0出发最多走t步问最多经过几个点。

思路:分开存负数点和整数点,然后枚举每个端点,某个点的距离*2+往反方向走距离<t。利用upper_bound()查找位置即可。(例如枚举左端点时,找出往右走最多的点)

 1 #include <bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4 vector <ll> f,z;
5 int main()
6 {
7 ll n,t;
8 scanf("%lld%lld",&n,&t);
9 for(int i=0;i<n;i++)
10 {
11 ll x;
12 scanf("%lld",&x);
13 if(x>0) z.push_back(x);
14 else f.push_back(-x);
15 }
16 sort(f.begin(),f.end());
17 sort(z.begin(),z.end());
18 ll ans=0;
19 for(int i=0;i<f.size();i++)
20 {
21 if(f[i]>t) break;
22 ll maxd=t-2*f[i];
23 ll res=0;
24 if(maxd>0) res=upper_bound(z.begin(),z.end(),maxd)-z.begin();
25 ans=max(ans,res+i+1);
26 }
27 for(int i=0;i<z.size();i++)
28 {
29 if(z[i]>t) break;
30 ll maxd=t-2*z[i];
31 ll res=0;
32 if(maxd>0) res=upper_bound(f.begin(),f.end(),maxd)-f.begin();
33 ans=max(ans,res+i+1);
34 }
35 printf("%lld\n",ans);
36 return 0;
37 }

Bonuses on a Line Gym - 102569B的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. 014.NET5_MVC_Razor扩展Html控件02

    第二种方法: 通过一个后台方法,返回一个不存在的html标签字符串,在读取的时候,通过后台方法去渲染成需要的标签和内容: 1. 定义一个普通类,类名称建议以TagHelper结尾,并且给类添加特性[H ...

  2. Beacon API

    Beacon API User Tracking https://caniuse.com/#feat=beacon Question & Solution Beacon API 不会延缓网页卸 ...

  3. AIoT & IoT

    AIoT & IoT Artificial Intelligence of Things Internet of Things AIoT === AI + IoT 人工智能物联网 === 人工 ...

  4. Apple & iOS & Device Screen Sizes and Orientations & React Native

    Apple & iOS & Device Screen Sizes and Orientations & React Native iOS devices https://de ...

  5. 10000星光值兑换一个的VAST将如何搅动NGK算力市场?

    加密数字货币是私人而非政府所发行的数字资产,具有自己的"货币"账户单位,在可以预见的未来三年之内,加密数字货币将覆盖至少全世界五分之一的人口.为此,NGK方面也做出了自己的努力,在 ...

  6. 磁盘使用率/文件大小查看指南du & df

    一.前言 磁盘使用率,文件大小查看是我们日常使用命令.这两个是配合使用的,磁盘使用率过高告警了,那么得找到对应的磁盘(df),然后找到对应磁盘下的哪个目录和文件占用了空间(du). df(Disk f ...

  7. 若依管理系统RuoYi-Vue(二):权限系统设计详解

    若依Vue系统中的权限管理部分的功能都集中在了系统管理菜单模块中,如下图所示.其中权限部分主要涉及到了用户管理.角色管理.菜单管理.部门管理这四个部分. 一.若依Vue系统中的权限分类 根据观察,若依 ...

  8. [转]Linux 线程实现机制分析 Linux 线程实现机制分析 Linux 线程模型的比较:LinuxThreads 和 NPTL

    转载地址:https://www.cnblogs.com/MYSQLZOUQI/p/4233630.html 自从多线程编程的概念出现在 Linux 中以来,Linux 多线应用的发展总是与两个问题脱 ...

  9. [转]Linux下scp的用法

    http://blog.51cto.com/yaksayoo/175719 scp就是secure copy,一个在linux下用来进行远程拷贝文件的命令.有时我们需要获得远程服务器上的某个文件,该服 ...

  10. HTML5中对于块级元素和行内元素的总结

    转自:https://www.cnblogs.com/iverson666/p/9169274.html块级元素:块级大多为结构性标记 <address>...</adderss&g ...