QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#16606. Sorting

统计

Given $n$ pairs $(a_i, b_i)$, define $f(i, j, k) = a_i b_j + a_j b_k + a_k b_i$.

We need to sort these $n$ pairs such that for any three consecutive pairs $i, i+1, i+2$ after sorting, the condition $f(i, i+1, i+2) \ge f(i+2, i+1, i)$ holds. Construct such an ordering.

Input

  • $n$
  • $a_1 \ b_1$
  • $\dots$
  • $a_n \ b_n$

Output

If a solution exists, output a permutation of $1 \sim n$ in a single line; otherwise, output $-1$.

Examples

Input 1

3
10 70
30 40
50 60

Output 1

2 3 1

Note 1

After sorting, we get $(30, 40), (50, 60), (10, 70)$. $f(1, 2, 3) = 5700$, $f(3, 2, 1) = 4700$.

Input 2

4
99 99
11 11
88 88
55 55

Output 2

2 4 3 1

Constraints

$3 \le n \le 1000$, $1 \le a_i, b_i \le 10^9$.

Subtasks

Subtask ID Score Constraints
1 2 $n \le 10$
2 8 $n \le 18$
3 22 $m = \sqrt{n} \in \mathbb{Z}$, and $a_i = \lfloor(i-1)/m+1\rfloor$, $b_i = (i-1) \pmod m + 1$
4 68 None

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.