Skip to main content
Back to problems
Codeforces
Medium
Arrays
Sorting
Greedy
George and Round

Determine how many tasks George can finish before a round ends, given a sequence of task positions and a rule that processes them in increasing order of appearance.

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

Problem

George has a list of tasks arranged in an array. He wants to process them in a round where tasks are handled in a specific order based on their positions. Your job is to determine how many tasks can be completed before the round finishes under the given processing rule.

A practical way to think about the problem is that George must scan the array, keep track of which required positions have been reached, and count the work completed in the correct order.

Goal

Compute the final count according to the rule described by the input sequence.

Input Format

  • The first line contains an integer nn.
  • The second line contains nn integers describing the array.

Output Format

  • Print one integer: the answer for the round.

Constraints

  • 1n1051 \le n \le 10^5
  • Array values fit in 32-bit signed integers
  • Time complexity should be near linear or O(nlogn)O(n \log n)

Hints

  • Track the positions you care about while scanning the array once.
  • Sorting or counting may help depending on how the order is enforced.

Input Format

  • Integer nn
  • Array of nn integers

Output Format

  • A single integer answer

Constraints

  • 1n1051 \le n \le 10^5
  • Use an approach efficient enough for large arrays
Examples
Sample cases returned by the problem API.

Example 1

Input

5
1 3 2 5 4

Output

5

Explanation

All elements can be processed in the required order, so the total count is 5.

Example 2

Input

4
2 1 4 3

Output

4

Explanation

The scan still allows all required elements to be completed by the end of the round.

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.