Universal Cup Judging System

Universal Cup

Time Limit: 2.5 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

有 $n$ 张卡片排成一行,其中 $n$ 是一个奇数。每张卡片的两面都写有数字。对于第 $i$ 张卡片,$a_i$ 朝上,$b_i$ 朝下。

Grammy 想要最大化所有朝上的数字的中位数。为了达到这个目的,她最多可以进行一次以下操作:

  • 选择一个区间 $[l, r]$ 并翻转该区间内的所有卡片。翻转后,对于 $i \in [l, r]$,卡片 $b_i$ 将朝上,$a_i$ 将朝下。

请帮助 Grammy 计算在她采取最优策略下,所有朝上的数字的中位数。

回想一下,一个数字序列的中位数是该序列中第 $\frac{n+1}{2}$ 大的数。

输入格式

第一行包含两个整数 $n$ ($1 \le n < 3 \cdot 10^5, n \pmod 2 = 1$),表示卡片的数量。

接下来 $n$ 行,每行包含两个整数 $a_i, b_i$ ($1 \le a_i, b_i \le 10^9$),分别表示每张卡片初始时朝上的数字和朝下的数字。

输出格式

输出一个整数,表示在 Grammy 的最优策略下,所有朝上的数字的中位数。

样例

样例输入 1

5
3 6
5 2
4 7
6 4
2 8

样例输出 1

6

样例输入 2

1
2 1

样例输出 2

2

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.