【Codeforces Round 332 (Div 2)C】【貪心】Day at the Beach 最多區間數劃分使得區間排序構成全域性排序
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.
At the end of the day there werencastles
built by friends. Castles are numbered from1ton
Squidward suggested the following process of sorting castles:
- Castles are split intoblocks — groups ofconsecutivecastles. Therefore the block fromitojwill include castlesi, i + 1, ..., j. A block may consist of a single castle.
- The partitioning is chosen in such a way that every castle is a part ofexactlyone block.
-
Each block is sorted independently from other blocks, that is the sequenceh
- The partitioning should satisfy the condition that after each block is sorted, the sequencehibecomes sorted too. This may always be achieved by saying that the whole sequence is a single block.
Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.