Eating apples
Practice
2.2 (17 votes)
Algorithms
Quick sort
Sorting
Problem
84% Success 1346 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:
- 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.
- 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.
Sample Input
5 1 4 6 7 2 3 2 5 3 7
Sample Output
0 4 2 1 3
Explanation
-
Code Editor
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
Submissions
Please login to view your submissions
Similar Problems
Points:20
15 votes
Tags:
EasyQuick SortSorting
Points:20
31 votes
Tags:
AlgorithmsEasyQuick Sort
Points:20
272 votes
Tags:
Binary SearchEasyOpenSorting
Editorial
Login to unlock the editorial
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