P2652 Straight Flush
Background
A straight flush refers to some playing cards whose suits are the same and whose ranks are consecutive.
Description
Now I have $n$ playing cards, but they may not form a straight flush. I want to know the minimum number of cards I need to replace so that all $n$ cards form a straight flush.
Input Format
The first line contains an integer $n$, indicating the number of playing cards.
Then $n$ lines follow, each containing two integers $a_{i}$ and $b_{i}$. Here, $a_{i}$ denotes the suit of the $i$-th card, and $b_{i}$ denotes the rank of the $i$-th card.
Output Format
Output a single integer on one line, indicating the minimum number of cards that need to be replaced to achieve the goal.
Explanation/Hint
- For $30\%$ of the testdata, $n \le 10$.
- For $60\%$ of the testdata, $n \le 10^{5}$, $1 \le a_{i} \le 10^{5}$, $1 \le b_{i} \le n$.
- For $100\%$ of the testdata, $n \le 10^{5}$, $1 \le a_{i}, b_{i} \le 10^{9}$.
Translated by ChatGPT 5