Choose the minimum number of plugged-in sockets needed to use all devices in order.
You are given a row of sockets, each of which can hold at most one device. Initially, some sockets may already be occupied. A sequence of devices arrives one by one, and each device must be connected to a free socket before it can be used.
For each device in the given order, determine whether it can be plugged in immediately using the available sockets. If so, occupy one socket with that device. If not, the process cannot continue.
Return the maximum number of devices that can be successfully connected before you run out of usable sockets.
This is a straightforward simulation / greedy counting task: track how many sockets are currently available and stop once the next device cannot be placed.
Input Format
The input format is the standard Codeforces-style format for a single test case.
- The first line contains the initial number of available sockets.
- The next line describes the arriving devices or socket usage sequence.
Because the original statement text is not provided here, treat the exact parsing details as problem-specific and focus on the core task: simulate socket availability in order.
Output Format
Print a single integer: the number of devices that can be connected before the sockets are no longer sufficient.
Constraints
- Use an simulation.
- Handle small edge cases such as no devices or no free sockets.
- Exact original numeric bounds are not available from the source metadata.
Example 1
Input
3 1 1 1 1
Output
3
Explanation
With 3 sockets available initially, only the first 3 devices can be connected. The 4th device cannot be plugged in.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.