Skip to content

Latest commit

ย 

History

History

BOJ_2437_์ €์šธ

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๋ฐฑ์ค€ #2437 ์ €์šธ

  • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์Šคํ„ฐ๋”” ๋ฌธ์ œ ํ’€์ด์ž…๋‹ˆ๋‹ค.
  • ๋ฐฑ์ค€ 2437๋ฒˆ ์—์„œ ํ’€์–ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ์„ค๋ช…

์ €์šธ

ํ•˜๋‚˜์˜ ์–‘ํŒ” ์ €์šธ๋กœ ๋ฌผ๊ฑด์˜ ๋ฌด๊ฒŒ๋ฅผ ์ธก์ •ํ•˜๋ ค๊ณ  ํ•œ๋‹ค.
์ €์šธ ์–‘ํŒ”์˜ ๊ธธ์ด๋Š” ๊ฐ™๊ณ , ํ•œ์ชฝ์—๋Š” ์ €์šธ์ถ”๋งŒ, ๋‹ค๋ฅธ ์ชฝ์—๋Š” ๋ฌผ๊ฑด๋งŒ ๋†“์„ ์ˆ˜ ์žˆ๋‹ค.

๋ฌด๊ฒŒ๊ฐ€ ์–‘์˜ ์ •์ˆ˜์ธ N๊ฐœ์˜ ์ €์šธ์ถ”๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ด ์ถ”๋“ค์„ ์‚ฌ์šฉํ•˜์—ฌ ์ธก์ •ํ•  ์ˆ˜ ์—†๋Š”
์–‘์˜ ์ •์ˆ˜ ๋ฌด๊ฒŒ ์ค‘ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฌด๊ฒŒ๊ฐ€ ๊ฐ๊ฐ 3, 1, 6, 2, 7, 30, 1์ธ 7๊ฐœ์˜ ์ €์šธ์ถ”๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ,
์ด ์ถ”๋“ค๋กœ ์ธก์ •ํ•  ์ˆ˜ ์—†๋Š” ์–‘์˜ ์ •์ˆ˜ ๋ฌด๊ฒŒ ์ค‘ ์ตœ์†Ÿ๊ฐ’์€ 21์ด๋‹ค.

ํ’€์ด

  1. ์ถ”์˜ ๋ฌด๊ฒŒ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.
  2. ์ธ๋ฑ์Šค 0๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ํ™•์ธ. ์ˆซ์ž๊ฐ€ (๋ˆ„์ ํ•ฉ + 1) ์ดํ•˜๋ผ๋ฉด ๋ˆ„์ ํ•ฉ + 1๊นŒ์ง€์˜ ์ˆซ์ž๋“ค์€ ๊ธฐ์กด์˜ ์ˆซ์ž๋“ค์˜ ์กฐํ•ฉ์œผ๋กœ ๋ชจ๋‘ ํ‘œํ˜„ ๊ฐ€๋Šฅํ•˜๋‹ค.
  3. ์ˆซ์ž๊ฐ€ (๋ˆ„์ ํ•ฉ + 2) ์ด์ƒ์ด๋ผ๋ฉด ๊ธฐ์กด ์ˆซ์ž๋“ค์˜ ์กฐํ•ฉ์œผ๋กœ (๋ˆ„์ ํ•ฉ + 1) ํ‘œํ˜„์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ (๋ˆ„์ ํ•ฉ + 1)์„ ์ถœ๋ ฅํ•œ๋‹ค.
from sys import stdin

def solution(weight):
    weight.sort()
    sum = 0
    for w in weight:
        if w >= sum + 2:
            return sum + 1
        else:
            sum += w
    return sum + 1

n = int(stdin.readline())
weight = list(map(int, stdin.readline().split()))
print(solution(weight))
from sys import stdin

n = int(stdin.readline().strip())
a = list(map(int,stdin.readline().split()))
a.sort()
s = 1

for i in range(n):
    if a[i] > s:
        break
    s += a[i]

print(s)