A dice tower
Practice
4.8 (8 votes)
Greedy algorithms
Algorithms
Basics of greedy algorithms
Greedy algorithm
Problem
89% Success 2831 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Bob is a big fan of cubical dices. He builds a dice tower by stacking the dice one on top of the other. A cubical dice and a dice tower are displayed as follows:

                                                ​​​​​​        ​​​​​        

Lee was given an integer $$N$$. He set out to build a tower with a minimum height, with the sum of points on all of its outer surfaces equaling the provided number $$N$$ (outer surface: the side surface, the top, and bottom faces).

You had to assist Lee in calculating the minimum number of dice needed to build the tower.

 Input format

  • The first line contains an integer $$T$$ denoting the number of test cases.
  • The first line of each test case contains an integer $$N$$.

Output format

For each test case, print the only integer that denotes the number of dices in the required tower in a new line. If no such tower exists, print $$-1$$.

Constraints

\(1 \le T \le 100000\\ 1 \le N \le 1000000000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
57 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:10
2 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms
Points:10
23 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms