ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

2141๋ฒˆ: ์šฐ์ฒด๊ตญ

์ฒซ์งธ ์ค„์— N(1≤N≤100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” X[1] A[1], X[2] A[2], …, X[N] A[N]์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฒ”์œ„๋Š” |X[i]|≤1,000,000,000, 0≤A[i]≤1,000,000,000 ์ด๋ฉฐ ๋ชจ๋“  ์ž…๋ ฅ์€ ์ •์ˆ˜์ด๋‹ค.

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ์ฒ˜์Œ ๋ฌธ์ œ๋ฅผ ์ ‘ํ•˜์˜€์„ ๋•Œ๋Š” ๋‚˜๋ผ์—์„œ ๊ฐ ์‚ฌ๋žŒ๋“ค๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ์˜ ํ•ฉ์ด ์ตœ์†Œ๊ฐ€ ๋˜๋Š” ์œ„์น˜์˜ ์˜๋ฏธ๋ฅผ ์ดํ•ดํ•˜์ง€ ๋ชปํ–ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์‹œ๊ฐ„๋ณด๋‹ค ๋ฌธ์ œ์—์„œ ์˜๋ฏธํ•˜๋Š” ๋ฐ”๋ฅผ ์ƒ๊ฐํ•˜๋Š” ๋ฐ๊นŒ์ง€ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ๋” ์†Œ์š”๋œ ๊ฒƒ ๊ฐ™๋‹ค.

 

 ์ฆ‰ ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ค‘๊ฐ„ ๊ฐ’์„ ๊ณ„์‚ฐํ•˜๊ณ , ๊ฐ ๋งˆ์„์˜ ๋ฒˆํ˜ธ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ•œ๋‹ค. ์ •๋ ฌ๋œ ๋งˆ์„์„ ๊ธฐ์ค€์œผ๋กœ ํ•˜๋‚˜์”ฉ ์ธ๊ตฌ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜์—ฌ ์ค‘๊ฐ„๊ฐ’๊ณผ ๊ฐ€์žฅ ๊ทผ์ ‘ํ•œ ๋งˆ์„์„ ์ฐพ์•„ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin

TOWN = 0
POP = 1

if __name__ == "__main__":
    N = int(stdin.readline())
    info = sorted([list(map(int, stdin.readline().split())) for _ in range(N)])

    mid = sum(population for _, population in info) // 2
    temp, idx = 0, 0

    while temp < mid:
        temp += info[idx][POP]
        idx += 1

    '''
    ์•„๋ž˜์™€ ๊ฐ™์€ Test Case ์ฒ˜๋ฆฌ์šฉ, N == 2์ธ ๊ฒฝ์šฐ๋ฅผ ํŒ๋‹จํ•˜์ง€ ์•Š์œผ๋ฉด 99%์—์„œ ์˜ค๋‹ต
    case1       case2
    2           2
    1 1         1 1
    2 1         2 2
    case 1์˜ ๊ฒฝ์šฐ, 1์„ ์ถœ๋ ฅํ•˜์—ฌ์•ผ ํ•จ (๋งˆ์„์˜ ์ธ๊ตฌ์ˆ˜๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ, ๋ฒˆํ˜ธ ์ˆœ๋Œ€๋กœ ์ถœ๋ ฅ)
    case 2์˜ ๊ฒฝ์šฐ, 2๋ฅผ ์ถœ๋ ฅํ•˜์—ฌ์•ผ ํ•จ (ํ™€์ˆ˜์ธ ๊ฒฝ์šฐ)
    '''
    if N == 2:
        print(info[1][TOWN] if info[0][POP] < info[1][POP] else info[0][TOWN])
    else:
        print(info[idx - 1][TOWN])

 

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€