QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#2038. 排序装置

統計

由于疫情原因,你在家待了几个月,于是决定探索一下父母地下室里的东西。在众多无用的物品中,你发现了一个奇怪的物体——一台六十年代用于教授排序算法的排序装置。该装置包含 $N$ 个有序的槽位,设备开启后,这些槽位会被初始化为不同的整数,同时还有一个用于跟踪成本的屏幕。作为用户,你可以执行交换操作。一次交换操作允许你交换位置 $i$ 和 $j$ 上的元素,总成本为 $A \cdot |i - j| + B$,其中 $A$ 和 $B$ 是写在设备背面的参数。既然你一直在研究排序算法,你一定知道如何以最小的成本对这些数字进行排序,对吧?

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 2 \cdot 10^5$),表示机器拥有的槽位数量。 下一行包含 $N$ 个以空格分隔的整数,其绝对值不超过 $10^9$,这是机器开启后生成的数字。 最后一行包含两个正整数 $A$ 和 $B$,来自机器规格说明,$1 \le A, B \le 1000$。

输出格式

第一行输出排序所需的最小成本。 第二行输出 $K$,即完成排序所需的交换次数。 接下来的 $K$ 行输出交换操作的描述。每行输出两个数字,表示要交换的元素的下标,中间用空格分隔。下标从 $1$ 开始。如果存在多种方案的总成本相同,你可以输出其中任意一种。

样例

样例输入 1

4
42 35 13 21
1 1

样例输出 1

7
3
1 3
3 4
2 3

样例输入 2

6
6 5 4 3 2 1
5 3

样例输出 2

54
3
3 4
2 5
1 6

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.