Problem 2670 --Sort II - Minimum Cost Sort

2670: Sort II - Minimum Cost Sort

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $2$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签 STL

Minimum Cost Sort

You are given n integers wi(i=0,1,...,n−1) to be sorted in ascending order. You can swap two integers wi and wj. Each swap operation has a cost, which is the sum of the two integers wi+wj. You can perform the operations any number of times. 

Write a program which reports the minimal total cost to sort the given integers.

In the first line, an integer n is given. In the second line, n integers wi(i=0,1,2,...n−1) separated by space characters are given.
Print the minimal cost in a line.
5
1 5 3 4 2
7

1≤n≤1,000

0≤wi≤10^4

wi are all different

推荐代码 查看2670 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$9 $ms] 囧囧JOJO 756671 2021-06-13 23:21:56
内存最少[$2088 $KB] 囧囧JOJO 756671 2021-06-13 23:21:56
第一AC 囧囧JOJO 756671 2021-06-13 23:21:56
第一挑战 囧囧JOJO 756671 2021-06-13 23:21:56

赛题来源/所属竞赛 会津大学《挑战数据结构与算法》 挑战数据结构与算法

竞赛编号 竞赛名称 竞赛时间 访问比赛