A small parcel-sealing station receives parcels in three size classes — small, medium, and large — and currently has a backlog of a small parcels, b medium parcels, and c large parcels waiting to be sealed. The station's machine has two independent sealing heads. Each second, the machine may either seal two parcels that belong to two different size classes at once (one head working each parcel), or, if only one size class still has a backlog, seal a single parcel from that class using just one head. The machine keeps working, second by second, until every parcel from every class has been sealed. Determine the minimum number of seconds needed to clear the entire backlog.
A single line containing three integers a, b, and c — the number of pending small, medium, and large parcels.
Print a single integer: the minimum number of seconds required to seal all pending parcels.
Example 1
Input
1 4 2
Expected
4
Explanation
The medium class alone has 4 parcels, more than small and large combined (1+2=3), so medium alone sets a floor of 4 seconds (at most one medium parcel is sealed per second). This is achievable: second 1 pairs medium+large, second 2 pairs medium+large (large now empty), second 3 pairs medium+small (small now empty), and second 4 seals the last medium alone. That is exactly 4 seconds, the minimum possible.
Example 2
Input
5 0 0
Expected
5
Explanation
Only the small class has any backlog (5 parcels), and the other two classes are already empty, so no pairing is ever possible — one small parcel must be sealed per second using a single head, giving exactly 5 seconds.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →