Cheerio Contest 3 P4 - Bit Flips

View as PDF

Submit solution


Points: 12
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

You have an array a of length N. In one operation, you can choose a number in the array and flip one of its bits, as long as the resultant number is non-negative and strictly less than 230. What is the minimum number of operations required to turn the array into a non-decreasing sequence?

Constraints

For all subtasks:

2N100

0ai<230

Input Specification

The first line contains a single integer N.

The second line contains N integers ai.

Output Specification

Output the minimum number of operations required to turn the array into a non-decreasing sequence.

Sample Input

Copy
5
10 7 8 3 4

Sample Output

Copy
3

Explanation for Sample Output

A possible final array could be [2,7,8,11,12], which takes 3 moves to transition to.


Comments

There are no comments at the moment.