Universal Cup Judging System

Universal Cup

Time Limit: 3 s Memory Limit: 16 MB Total points: 100 Difficulty: [show]
Statistics

Otrzymujesz ciąg $a_0, \dots, a_{2n}$. Początkowo wszystkie liczby są równe zero.

Dostępnych jest $n$ operacji. $i$-ta operacja jest reprezentowana przez dwie liczby całkowite $l_i, r_i$ ($1 \le l_i < r_i \le 2n$, $1 \le i \le n$), które przypisują wartość $i$ elementom $a_{l_i}, \dots, a_{r_i-1}$. Gwarantuje się, że wszystkie $2n$ liczb $l_1, l_2, \dots, l_n, r_1, r_2, \dots, r_n$ jest różnych.

Musisz wykonać każdą operację dokładnie raz, w dowolnej kolejności.

Chcesz zmaksymalizować liczbę takich $i$ ($0 \le i < 2n$), dla których $a_i \neq a_{i+1}$ po wykonaniu wszystkich $n$ operacji. Wypisz tę maksymalną liczbę.

Wejście

Pierwsza linia zawiera liczbę całkowitą $n$ ($1 \le n \le 5 \times 10^3$).

$i$-ta linia z kolejnych $n$ linii zawiera parę liczb całkowitych $l_i, r_i$ ($1 \le l_i < r_i \le 2n$). Gwarantuje się, że wszystkie $2n$ liczb $l_1, l_2, \dots, l_n, r_1, r_2, \dots, r_n$ jest różnych.

Wyjście

Wypisz jedną liczbę całkowitą reprezentującą odpowiedź w jednej linii.

Przykład

Wejście 1

5
2 3
6 7
1 9
5 10
4 8

Wyjście 1

9

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.