[๋ฐฑ์ค€]#2437 Python๐Ÿคฏ

Jiyoonยท2021๋…„ 7์›” 29์ผ
0

Algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
2/24
post-custom-banner

๋ฐฑ์ค€ 2437๋ฒˆ - ์ €์šธ

https://www.acmicpc.net/problem/2437

์ „์ฒด์ฝ”๋“œ

import sys
input = sys.stdin.readline

N= int(input())
weight= list(map(int,input().split()))
weight.sort()
num= 1
#๋งŒ๋“ค ์ˆ˜ ์—†๋Š” ์ˆ˜ ์ฐพ๊ธฐ
for i in weight:
  if num < i:
    break
  num+= i

print(num)

๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ์ดํ•ดํ–ˆ๋‹ค,,,

์ฐธ๊ณ ํ•œ ์ฝ”๋“œ -> https://velog.io/@sch804/ํŒŒ์ด์ฌ-๋ฐฑ์ค€-2437๋ฒˆ-์ €์šธ

๋‚˜๋Š” ์ดํ•ดํ•˜๋Š” ๋ฐ์— ์˜ค๋ž˜ ๊ฑธ๋ ค์„œ ์ถ”๊ฐ€์ ์ธ ์„ค๋ช…์„ ๋ง๋ถ™์—ฌ๋ณธ๋‹ค.
์ฒ˜์Œ ์‹œ์ž‘ํ•˜๋Š” ๊ฐ’(num)์„ 1๋กœ ๋†“๊ณ  weight ์˜ ์›์†Œ ๊ฐ’์„ ๋”ํ•ด๋‚˜๊ฐ„๋‹ค.
a~g ๊นŒ์ง€์˜ ํ•ฉ์„ n์ด๋ผ๊ณ  ํ–ˆ์„ ๋•Œ(a~g ์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ๋“ค๋ผ๋ฆฌ์˜ ํ•ฉ์ด 1~n ๊นŒ์ง€ ์žˆ๋‹ค๋Š” ๋œป), ๊ทธ ๋‹ค์Œ์˜ h ๊ฐ’์„ ๋‘ ๊ฒฝ์šฐ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค.

  1. 1+n ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ๊ฐ’์ผ ๋•Œ:
    a~g ๊นŒ์ง€์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ์˜ ํ•ฉ์ด 1~n ์ด๊ธฐ ๋–„๋ฌธ์— ๊ฐ€๋Šฅํ•œ ํ•ฉ์ด 1+n ์—์„œ n+h ๊นŒ์ง€ ๋Š˜์–ด๋‚œ๋‹ค. ๊ทธ ๋‹ค์Œ ์›์†Œ๋ฅผ ๋ณผ ๋• num = 1+n+h
  2. 1+n ๋ณด๋‹ค ํด ๋•Œ:
    n ๊ณผ h ์˜ ์ค‘๊ฐ„์— ์žˆ๋Š” ๊ฐ’์ธ 1+n ์€ ์ ˆ๋Œ€ ๋‚˜์˜ฌ ์ˆ˜๊ฐ€ ์—†์œผ๋ฏ€๋กœ 1+n ์ด ๋‚˜์˜ฌ ์ˆ˜ ์—†๋Š” ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’์— ์†ํ•œ๋‹ค.

๋Š๋‚€์ 

๊ต‰์žฅํžˆ ๊ฐ„๋‹จํ•ด ๋ณด์ด์ง€๋งŒ ์ƒ๊ฐํ•ด๋‚ด๊ธฐ๊ฐ€ ์–ด๋ ค์› ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ๊ดœํžˆ ๊ณจ๋“œ3์ด ์•„๋‹Œ๋“ฏ.

post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€