QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#15634. 公平分配

الإحصائيات

NWERC 后 KIT 队伍正在享用庆祝晚餐。照片由 Christopher Weyand 拍摄

你们大学的队伍正在庆祝今年在卡尔斯鲁厄(Karlsruhe)举行的 NWERC 中的杰出表现。在当地一家餐馆享用了一顿美味的晚餐后,大家准备结束这一天。明天的回家旅程将会很漫长。

在准备结账时,你们的小组发现这家餐馆不收现金。此外,现在重新分账单也已经太晚了。措手不及之下,每个人都开始打开钱包,把一些现金放在桌子上。必须有人用信用卡支付整张账单,并收走这些现金。

每个人 $i$ 在当晚消费了 $€b_i$,但有 $€a_i$ 的现金可以用于支付集体账单(如果由其他人付款)。为了保持公平,小组不希望支付最终账单(并拿走现金池中的钱)的人最终支付的金额超过其个人应付的份额。 因此,如果第 $i$ 个人是付款的人,那么在扣除其他人的现金贡献后,账单的剩余部分不应超过他们自己应付的账单份额 $€b_i$。

请帮助该小组确定谁应该支付最终账单。

输入格式

输入包含:

  • 第一行包含一个整数 $n$($2 \le n \le 10^5$),表示你们晚餐小组的人数。
  • 接下来 $n$ 行,第 $i$ 行包含两个整数 $a_i$ 和 $b_i$($1 \le a_i, b_i \le 1000$),分别表示如果由其他人付款时第 $i$ 个人会贡献的现金量,以及他们自己应付的账单份额。

输出格式

如果没有合适的人来结账,输出 "impossible"。否则,输出一个整数 $i$($1 \le i \le n$),表示结账人的编号。

如果有多个可行解,你可以输出其中任意一个。

样例

输入样例 1

3
4 3
5 4
1 3

输出样例 1

3

输入样例 2

5
1 4
8 1
1 4
2 5
4 6

输出样例 2

impossible

说明

总账单为 $€20$。如果第一个人结账,他们会从其他人那里得到 $€15$ 的现金,自己支付 $€5$,这超过了他们个人应付的份额 $4$。对其他每个人进行类似的推理表明,他们也需要支付超过自己应付份额的金额,因此没有合适的人来结账。

输入样例 3

8
4 3
5 8
7 2
1 9
6 3
2 6
5 7
8 6

输出样例 3

4

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.