====== 아령 ====== ===== 풀이 ===== * [[ps:problems:boj:1851]], [[ps:problems:boj:2322]], [[ps:problems:boj:2569]], [[ps:problems:boj:6223]]이 모두 동일한 문제이다. 풀이는 [[ps:problems:boj:1851]]을 참고. ===== 코드 ===== """Solution code for "BOJ 2322. 아령". - Problem link: https://www.acmicpc.net/problem/2322 - Solution link: http://www.teferi.net/ps/problems/boj/2322 Tags: [Greedy] """ def main(): n = int(input()) w = [int(x) for x in input().split()] min_w = min(w) orders = sorted(range(n), key=w.__getitem__) is_visited = [False] * n answer = 0 for i in range(n): if is_visited[i]: continue weights = [] cur = i while not is_visited[cur]: is_visited[cur] = True weights.append(w[cur]) cur = orders[cur] answer += min( sum(weights) + min(weights) * (len(weights) - 2), sum(weights) + min(weights) + min_w * (len(weights) + 1)) print(answer) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:플래티넘_1}}