Non-consecutive Summands
Time limit1sMemory limit128 MB
Split a positive integer into the most distinct parts possible, none of which are consecutive.
- Level
Medium5 of 10
- Topics
- Greedy, Math, Binary search
- Solved
- No attempts yet
Problem
You are given a positive integer . You want to write it as a sum of positive integers while obeying both of these rules:
- No integer may be used more than once (each integer appears at most once).
- No two consecutive integers may be used together (for example, and cannot both appear).
Subject to these rules, make the number of summands as large as possible. Find that maximum number of summands.
Input
The first and only line contains an integer ().
Output
Print a single integer: the maximum number of summands in such a decomposition.