PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh_07
Tester: mridulahi
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
You distributed N chocolates to some children, but don’t remember how many children there were.
Each child received either 1 or 2 chocolates. Find the minimum and maximum possible number of children.
EXPLANATION:
The number of children will be maximum if each child receives as few chocolates as possible: that is, when each child received 1 chocolate.
In this case, clearly the number of children would be N.
Conversely, the number of children will be minimum if each child (except 1, when N is odd) receives 2 chocolates.
In this case, the number of children is \frac{N}{2} when N is even, and 1 + \frac{N-1}{2} when N is odd.
This can be succinctly written as \left\lceil \frac{N}{2} \right\rceil, where \left\lceil \ \ \right\rceil denotes the ceiling function.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
n = int(input())
print((n+1)//2, n)