Skip to main content
Back to problems
Codeforces
Easy
Arrays
Strings
Greedy
Sockets

Choose the minimum number of plugged-in sockets needed to use all devices in order.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

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 O(n)O(n) simulation.
  • Handle small edge cases such as no devices or no free sockets.
  • Exact original numeric bounds are not available from the source metadata.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.