AmazonOA #45
Min Operations to Ship Products
Estimated MediumJudge-ready
One shipment can send two items from different locations, or a single item on its own. Find the minimum number of shipments needed to send all items.
Input
The first line contains n (1..100000), and the second line contains n locations (1..10⁹).
Output
Output a single integer answer.
Example 1
Input:
5
1 8 6 7 7
Output:
3
Example 2
Input:
3
1 1 1
Output:
3
Example 3
Input:
2
1 2
Output:
1
Example notes
Example 1: the two 7s are paired with 1 and 8 respectively, and 6 is shipped alone, for 3 in total. Example 2: items from the same location cannot ship together, so 3 shipments are needed. Example 3: the two locations ship together, 1 shipment.
Editorial
Loading solution…