题目链接: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. 计量经济学导论10:ARIMA模型

    目录 ${\rm ARIMA}$ 模型 滞后算子 ${\rm MA}(q)$ 模型 ${\rm MA}(1)$ 模型 ${\rm MA}(q)$ 模型 ${\rm AR}(p)$ 模型 ${\rm A ...

  2. PWA All In One

    PWA All In One chrome://apps/ PWA Progressive Web App 可安装,添加到主屏 离线使用 轻量,快速 基于 Web 技术一套代码多端复用(移动端,桌面端 ...

  3. 微信小程序-导航 & 路由

    微信小程序-导航 & 路由 页面跳转 页面路由 页面栈, 框架以栈的形式维护了当前的所有页面. https://developers.weixin.qq.com/miniprogram/dev ...

  4. Elastic Search 原理剖析

    Elastic Search 原理剖析 Elasticsearch 是一个开源的分布式 RESTful 搜索和分析引擎,能够解决越来越多不同的应用场景. 搜索引擎 refs https://www.e ...

  5. TypeScript 3.7 RC & Assertion Functions

    TypeScript 3.7 RC & Assertion Functions assertion functions, assert https://devblogs.microsoft.c ...

  6. c++ string与wstring转换

    wchar_t to char #include <comdef.h> const wchar_t* exepath = L"d:\\中文 路径\\中文 路径.exe" ...

  7. BGV币与YFI币、YFII币存在着怎样的相关性?

    大多数的玩家并没有长期的打算,而是更倾向于关注短期利好的币种.比如最近在圈内赚足眼球的YFI,之所以能够成为明星角色,并非它的技术和平台,而是因为它在短期就创造了86倍的暴涨.YFI币的暴涨在某种程度 ...

  8. Redis的数据结构与应用场景

    一.Redis简介 Redis 是一个开源的使用 ANSI C 语言编写.遵守 BSD 协议.支持网络.可基于内存.分布式.可选持久性的键值对(Key-Value)存储数据库,并提供多种语言的 API ...

  9. Fast-RTPS简介

    RTPS即DDS中的主要核心通信部分.它提供实时高效的去中心化publish/subscribe通信机制.是ROS-2的核心底层通信组件,也是未来机器人/无人驾驶领域一个必然的方向. 资料参考: ht ...

  10. idea将文件push之后如何回退