Advertisement
helloInfinity

explanation of array sharpening codeforces div2 - 616 - problem B

Sep 8th, 2022
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TeXgraph 0.58 KB | Software | 0 0
  1. How to know if we can make the prefix [1;k] strictly increasing? We just have to consider the following simple greedy solution: take down values to 0,1,…,k−1 (minimal possible values). It's possible if and only if ai≥i1 holds in the whole prefix.
  2.  
  3. Similarly, the suffix [k;n] can be made strictly decreasing if and only if ai≥ni holds in the whole suffix.
  4.  
  5. Using these simple facts, we can compute the longest prefix we can make strictly increasing, and the longest suffix we can make strictly decreasing in O(n). Then, we just have to check that their intersection is non-empty.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement