AmazonOA #63
Calculate Min Shipments (Warehouse Pairing)
Estimated MediumJudge-ready
One shipment sends two items from different warehouses, or a single item on its own; find the minimum number of shipments needed to send everything. This problem has the same rules as Amazon45 and keeps its own independent source number.
Input
The first line contains n (1..100000), and the second line contains n warehouse numbers (1..10⁹).
Output
Output a single integer answer.
Example 1
Input:
5
2 9 7 8 8
Output:
3
Example 2
Input:
2
1 1
Output:
2
Example 3
Input:
3
1 2 3
Output:
2
Example notes
Example 1: the two 8s are paired with 2 and 9 respectively, and 7 is shipped alone, 3 in total. Example 2: items from the same warehouse cannot be paired, 2 shipments. Example 3: pair any two items and ship the remaining one alone, 2 shipments.
Editorial
Loading solution…