Pen Testing
Time limit90sMemory limit1024 MB
Given N pens holding each ink amount from 0 to N-1 once, find two pens with at least N ink total, using write attempts that drain ink to probe them.
- Level
Medium6 of 10
- Topics
- Greedy, Implementation
- Solved
- No attempts yet
Problem
You have ballpoint pens. Each pen holds a distinct integer number of ink units between and , but the pens are given to you in random order, so you do not know how much ink each pen holds.
You are about to go on a trip to the South Pole, where there are no pens. Your luggage has room for only two pens. You also need to write many important postcards, so the two pens you choose must have a total of at least ink units.
The only way to learn about the pens is to pick one and try writing with it. If the write succeeds, that pen loses one unit of ink (and may now be empty). If it fails, the pen already had no ink left. You can repeat this as many times as you like, with the same pen or different pens.
Finally, you choose two pens to take on the trip. You succeed if the total ink remaining in those two pens is at least units.
You will be given test cases, and you must succeed in at least of them. All test data in this problem is visible.