欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1197B.Pillars
Pillars
There are pillars aligned in a row and numbered from to .
Initially each pillar contains exactly one disk. The -th pillar contains a disk having radius .
You can move these disks from one pillar to another. You can take a disk from pillar and place it on top of pillar if all these conditions are met:
- there is no other pillar between pillars and . Formally, it means that ;
- pillar contains exactly one disk;
- either pillar contains no disks, or the topmost disk on pillar has radius strictly greater than the radius of the disk you move.
When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.
You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all disks on the same pillar simultaneously?
Input
The first line contains one integer () — the number of pillars.
The second line contains integers , , ..., (), where is the radius of the disk initially placed on the -th pillar. All numbers are distinct.
Output
Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
Note
In the first case it is possible to place all disks on pillar using the following sequence of actions:
- take the disk with radius from pillar and place it on top of pillar ;
- take the disk with radius from pillar and place it on top of pillar ;
- take the disk with radius from pillar and place it on top of pillar ;
- take the disk with radius from pillar and place it on top of pillar .
Samples
4
1 3 4 2
YES
3
3 1 2
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |