์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€ (boj) ํŒŒ์ด์ฌ - 2798 ๋ธ”๋ž™์žญ

  • -

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/2798

 

2798๋ฒˆ: ๋ธ”๋ž™์žญ

๋ฌธ์ œ ์นด์ง€๋…ธ์—์„œ ์ œ์ผ ์ธ๊ธฐ ์žˆ๋Š” ๊ฒŒ์ž„ ๋ธ”๋ž™์žญ์˜ ๊ทœ์น™์€ ์ƒ๋‹นํžˆ ์‰ฝ๋‹ค. ์นด๋“œ์˜ ํ•ฉ์ด 21์„ ๋„˜์ง€ ์•Š๋Š” ํ•œ๋„ ๋‚ด์—์„œ, ์นด๋“œ์˜ ํ•ฉ์„ ์ตœ๋Œ€ํ•œ ํฌ๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฒŒ์ž„์ด๋‹ค. ๋ธ”๋ž™์žญ์€ ์นด์ง€๋…ธ๋งˆ๋‹ค ๋‹ค์–‘ํ•œ ๊ทœ์ •์ด ์žˆ๋‹ค. ํ•œ๊ตญ ์ตœ๊ณ ์˜ ๋ธ”๋ž™์žญ ๊ณ ์ˆ˜ ๊น€์ •์ธ์€ ์ƒˆ๋กœ์šด ๋ธ”๋ž™์žญ ๊ทœ์น™์„ ๋งŒ๋“ค์–ด ์ƒ๊ทผ, ์ฐฝ์˜์ด์™€ ๊ฒŒ์ž„ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ๊น€์ •์ธ ๋ฒ„์ ผ์˜ ๋ธ”๋ž™์žญ์—์„œ ๊ฐ ์นด๋“œ์—๋Š” ์–‘์˜ ์ •์ˆ˜๊ฐ€ ์“ฐ์—ฌ ์žˆ๋‹ค. ๊ทธ ๋‹ค์Œ, ๋”œ๋Ÿฌ๋Š” N์žฅ์˜ ์นด๋“œ๋ฅผ ๋ชจ๋‘ ์ˆซ์ž๊ฐ€ ๋ณด์ด๋„๋ก ๋ฐ”๋‹ฅ์— ๋†“๋Š”๋‹ค. ๊ทธ๋Ÿฐ ํ›„์— ๋”œ๋Ÿฌ๋Š” ์ˆซ์ž M์„ ํฌ๊ฒŒ

www.acmicpc.net

 

 

 

 

์นด๋“œ๋ฅผ 3๊ฐœ ๋ฝ‘๋Š” ๋ฌธ์ œ์ด๋ฏ€๋กœ for๋ฌธ์„ 3๋ฒˆ ์‚ฌ์šฉํ•˜์—ฌ 3์ค‘ for๋ฌธ์œผ๋กœ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ํƒ์ƒ‰ํ•˜๋ฉด ๋œ๋‹ค.

ํ•˜์ง€๋งŒ ์ด๋•Œ, ๊ฐ™์€ ์นด๋“œ๋ฅผ ๋ฝ‘๋Š”๊ฒฝ์šฐ๋Š” ์ œ๊ฑฐํ•ด์•ผ ํ•˜๋ฏ€๋กœ, if๋ฌธ์œผ๋กœ break๋ฅผ ๋งŒ๋“ค์–ด ๋ฌด์˜๋ฏธํ•œ ํƒ์ƒ‰์‹œ๊ฐ„์„ ์ค„์—ฌ์ค˜์•ผํ•œ๋‹ค.

 

 

 

 

 

n,m = map(int,input().split())
answer = []
card = list(map(int,input().split()))


for a in card:

    for b in card:
        if a==b : break  #๊ฐ™์€ ์นด๋“œ๋ผ๋ฉด break
        for c in card:
            if b==c or a==c: break  #๊ฐ™์€ ์นด๋“œ๋ผ๋ฉด break
            elif a+b+c <= m : 
                answer.append(a+b+c)
print(max(answer))
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.