AT_abc457_g.Catch All Apples
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
N apples fall on a number line. Apple i falls at coordinate Xi at time Ti.
You want to place some robots on the number line to collect all N apples. The robots can be placed at any coordinates.
Each robot starts operating from time 0 and can move freely along the number line at a speed of at most 1. Multiple robots may occupy the same coordinate at the same time. Each robot can collect apple i if and only if it is at coordinate Xi at time Ti.
Find the minimum number of robots needed to collect all apples.
有 N 个苹果落在一条数轴上。苹果 i 在时刻 Ti 落在坐标 Xi 处。
你想在数轴上放置若干机器人来收集全部 N 个苹果。机器人可以放置在任意坐标处。
每个机器人从时刻 0 开始工作,且沿数轴移动的速度至多为 1。多个机器人可以在同一时刻位于同一坐标。机器人当且仅当在时刻 Ti 恰好位于坐标 Xi 时,才能收集苹果 i。
求收集全部苹果所需的最少机器人数量。
输入格式
The input is given from Standard Input in the following format:
N
T1 X1
T2 X2
⋮
TN XN
输入从标准输入中按以下格式给出:
N
T1 X1
T2 X2
⋮
TN XN
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
4 0 2 1 0 2 1 2 3
输出#1
2
输入#2
5 0 1 0 2 0 3 0 4 0 5
输出#2
5
输入#3
8 10 4 4 2 7 10 5 3 1 9 0 6 3 8 0 9
输出#3
2
说明/提示
Sample 1 Explanation:
All apples can be collected with two robots by moving them as follows:
- Place robot 1 at coordinate 0 and robot 2 at coordinate 2.
- Time 0: Robot 2 collects apple 1.
- Time 1: Robot 1 collects apple 2. Move both robots in the positive direction at speed 1 until time 2.
- Time 2: Robot 1 collects apple 3 and robot 2 collects apple 4.
It is impossible to collect all apples with fewer than two robots, so output 2.
Constraints
- 1≤N≤3×105
- 0≤Ti≤3×105
- 0≤Xi≤3×105
- (Ti,Xi)=(Tj,Xj) (i=j)
- All input values are integers.
样例 1 解释:
所有苹果均可由两个机器人协作收集,具体移动方式如下:
- 将机器人 1 置于坐标 0 处,机器人 2 置于坐标 2 处。
- 时刻 0:机器人 2 收集苹果 1。
- 时刻 1:机器人 1 收集苹果 2;此后两机器人均以速度 1 向正方向移动,持续至时刻 2。
- 时刻 2:机器人 1 收集苹果 3,机器人 2 收集苹果 4。
无法用少于两个机器人收集全部苹果,因此输出 2。
约束条件
- 1≤N≤3×105
- 0≤Ti≤3×105
- 0≤Xi≤3×105
- (Ti,Xi)=(Tj,Xj)(当 i=j 时)
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?