Eating apples
Practice
2.2 (17 votes)
Algorithms
Quick sort
Sorting
Problem
84% Success 1340 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are staying at point \((1,\ 1)\) in a matrix \(10^9 \times 10^9\). You can travel by following these steps:

  1. If the row where you are staying has 1 or more apples, then you can go to another end of the row and can go up.
  2. Otherwise, you can go up.

The matrix contains \(N\) apples. The \(i^{th}\) apple is at point \((x_i,\ y_i)\). You can eat these apples while traveling. 

For each of the apples, your task is to determine the number of apples that have been eaten before.

Input format

  • The first line contains a single integer \(N\) \((1 \le N \le 10^5)\) denoting the number of apples.
  • The next \(N\) lines contain two integers\(x_i,\ y_i\) \((1 \le x_i,\ y_i \le 10^9)\) denoting the coordinates of the \(i^{th}\) apple.

Output format

Print \(N\) lines containing a single integer.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
7 votes
Tags:
Quick SortSortingAlgorithms
Points:20
158 votes
Tags:
AlgorithmsApprovedEasyImplementationOpenSortingTwo-pointer
Points:20
11 votes
Tags:
AlgorithmsArraysBinary treeEasyHash MapsImplementationOne-dimensionalQuick SortSorting