A13669 | Cakes for Clones
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You live on a number line. You are initially (at time moment $t = 0$ ) located at point $x = 0$ . There are $n$ events of the following type: at time $t_i$ a small cake appears at coordinate $x_i$ . To collect this cake, you have to be at this coordinate at this point, otherwise the cake spoils immediately. No two cakes appear at the same time and no two cakes appear at the same coordinate.
You can move with the speed of $1$ length unit per one time unit. Also, at any moment you can create a clone of yourself at the same point where you are located. The clone can't move, but it will collect the cakes appearing at this position for you. The clone disappears when you create another clone. If the new clone is created at time moment $t$ , the old clone can collect the cakes that appear before or at the time moment $t$ , and the new clone can collect the cakes that appear at or after time moment $t$ .
Can you collect all the cakes (by yourself or with the help of clones)?
You can move with the speed of $1$ length unit per one time unit. Also, at any moment you can create a clone of yourself at the same point where you are located. The clone can't move, but it will collect the cakes appearing at this position for you. The clone disappears when you create another clone. If the new clone is created at time moment $t$ , the old clone can collect the cakes that appear before or at the time moment $t$ , and the new clone can collect the cakes that appear at or after time moment $t$ .
Can you collect all the cakes (by yourself or with the help of clones)?
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 5000$ ) — the number of cakes.
Each of the next $n$ lines contains two integers $t_i$ and $x_i$ ( $1 \le t_i \le 10^9$ , $-10^9 \le x_i \le 10^9$ ) — the time and coordinate of a cake's appearance.
All times are distinct and are given in increasing order, all the coordinates are distinct.
Each of the next $n$ lines contains two integers $t_i$ and $x_i$ ( $1 \le t_i \le 10^9$ , $-10^9 \le x_i \le 10^9$ ) — the time and coordinate of a cake's appearance.
All times are distinct and are given in increasing order, all the coordinates are distinct.
输出格式
Print "YES" if you can collect all cakes, otherwise print "NO".
输入输出样例
输入 #1
3 2 2 5 5 6 1
输出 #1
YES
输入 #2
3 1 0 5 5 6 2
输出 #2
YES
输入 #3
3 2 1 5 5 6 0
输出 #3
NO
In the first example you should start moving towards $5$ right away, leaving a clone at position $1$ at time moment $1$ , and collecting the cake at position $2$ at time moment $2$ . At time moment $5$ you are at the position $5$ and collect a cake there, your clone collects the last cake at time moment $6$ .
In the second example you have to leave a clone at position $0$ and start moving towards position $5$ . At time moment $1$ the clone collects a cake. At time moment $2$ you should create a new clone at the current position $2$ , it will collect the last cake in future. You will collect the second cake at position $5$ .
In the third example there is no way to collect all cakes.
In the second example you have to leave a clone at position $0$ and start moving towards position $5$ . At time moment $1$ the clone collects a cake. At time moment $2$ you should create a new clone at the current position $2$ , it will collect the last cake in future. You will collect the second cake at position $5$ .
In the third example there is no way to collect all cakes.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted