Created
July 13, 2021 15:43
-
-
Save uchidama/20abdc60511f4671b92b4aca13dfd7bc to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 173 [ D - Chat in a Circle ] https://atcoder.jp/contests/abc173/tasks/abc173_d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
[問題] | |
https://atcoder.jp/contests/abc173/tasks/abc173_d | |
[解説] | |
https://youtu.be/IMwigbYzLbI?t=2853 | |
別例作って、ちゃんとモデル化して考えないとダメなんだろうなー | |
''' | |
import sys | |
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ | |
input = sys.stdin.readline | |
INF = 2 ** 63 - 1 | |
N = int(input()) | |
A = list(map(int, input().split())) | |
# 降順にソート。感じからして、大きい順にいれるで良さそう | |
A.sort(reverse=True) | |
# 足せる回数 | |
LIMIT_ADD = N - 1 | |
ans = 0 | |
# モデル化してみると、一番大きい数が足される回数は1回、他2回ずつ大きい数から足されるで最大 | |
for i,a in enumerate(A): | |
LOOP = 2 | |
if i == 0: | |
LOOP = 1 | |
for j in range(LOOP): | |
if LIMIT_ADD > 0: | |
ans += a | |
LIMIT_ADD -= 1 | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment