๊ธฐ๋ก๋ฐฉ

BOJ_11399 : ATM ๋ณธ๋ฌธ

CodingTest/Python

BOJ_11399 : ATM

Soom_1n 2022. 8. 30. 00:16

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

11399๋ฒˆ: ATM

์ฒซ์งธ ์ค„์— ์‚ฌ๋žŒ์˜ ์ˆ˜ N(1 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๊ฐ ์‚ฌ๋žŒ์ด ๋ˆ์„ ์ธ์ถœํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ Pi๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Pi ≤ 1,000)

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ ์ˆซ์ž์˜ ์ˆ˜์™€ ์ˆซ์ž๋“ค์˜ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ž…๋ ฅ๋œ๋‹ค.
  • ๊ฐ ๋ฆฌ์ŠคํŠธ ๋ณ„ ๋๋‚˜๋Š” ์‹œ๊ฐ„๋“ค์˜ ์ดํ•ฉ์˜ ์ตœ์†Œ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.
  • ๋ฌธ์ œ ์„ค๋ช…์€ ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด์ง€๋งŒ, ์ •๋ ฌ๋กœ ๊ฐ„๋‹จํžˆ ํ’€๋ฆฐ๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

import sys

n = int(sys.stdin.readline())

arr = list(map(int, sys.stdin.readline().rstrip().split()))
arr.sort()
sum_num = 0
for i in range(n):
    sum_num += sum(arr[:i+1])
print(sum_num)

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • ์ œํ•œ์‹œ๊ฐ„์ด 1์ดˆ์ธ ๋ฌธ์ œ์—ฌ์„œ ๋น ๋ฅธ ์ž…๋ ฅ์„ ์‚ฌ์šฉํ–ˆ๋‹ค.
  • ์ดํ•ฉ์ด ์ตœ์†Œ์‹œ๊ฐ„์ด ๋˜๋„๋ก ํ•˜๋ ค๋ฉด, ์ ์€ ์‹œ๊ฐ„์„ ๋จผ์ € ์ฒ˜๋ฆฌํ•˜๋ฉด ๋˜๋ฏ€๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ๋‹ค.
  • ๋ฆฌ์ŠคํŠธ ์›์†Œ๋ณ„ ์ฒ˜๋ฆฌ์‹œ๊ฐ„์˜ ํ•ฉ์€ ์ฒ˜์Œ๋ถ€ํ„ฐ ํ•ด๋‹น ์ธ๋ฑ์Šค๊นŒ์ง€์˜ ํ•ฉ์„ ์Šฌ๋ผ์ด์‹ฑ์œผ๋กœ ๊ตฌํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๋ฌธ์ œ๋ฅผ ์ฝ์–ด๋ณด๋‹ˆ ๊ทธ๋ฆฌ๋”” ๊ฐ™์•„์„œ ๋ณต์žกํ• ๊นŒ ๊ฑฑ์ •ํ–ˆ๋Š”๋ฐ ์ •๋ ฌ๋กœ ๊ฐ„๋‹จํžˆ ํ’€๋ ธ๋‹ค.

728x90