#DSU0000076. Cuộc chạy trốn của Neo (Neo’s Escape)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cuộc chạy trốn của Neo (Neo’s Escape)
Neo’s Escape
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Neo faces buttons in a row, with weight on button . He cannot move himself but may create a clone at any button, or move an existing clone left or right by one position.
A clone immediately presses every unpressed button it reaches. Each button is pressed at most once. Neo must press all buttons in a non-increasing order of their weights. Find the minimum number of clones required.
Neo may create multiple clones, each at any button. Once created, a clone can move only between adjacent buttons. Whenever a clone reaches an unpressed button, it must press that button immediately; it cannot pass through without pressing it.
Neo chooses when to create and move clones, provided every button is pressed exactly once and the weights in the order of pressing form a non-increasing sequence. Buttons having equal weights may be pressed in any order.
Input
The first line contains . The second contains the weights .
Output
Print one integer: the minimum number of clones required.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
4 3 2 1 5
Output
2
Explanation
Button must be pressed before all lower-weight buttons. Create one clone to press and a second clone to press , then move the latter along the buttons of weights . One clone cannot suffice: moving from weight toward weight would force it to press some smaller-weight buttons too early.