본문 바로가기
python-algorithm

백준 2535 아시아 정보올림피아드

by 무적김두칠 2022. 10. 18.

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

 

2535번: 아시아 정보올림피아드

첫 번째 줄에는 대회참가 학생 수를 나타내는 N이 주어진다. 단, 3 ≤ N ≤ 100이다. 두 번째 줄부터 N개의 줄에는 각 줄마다 한 학생의 소속 국가 번호, 학생 번호, 그리고 성적이 하나의 빈칸을 사

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def sol(n,nums):
    nums.sort(key=lambda x: x[2],reverse=True)
    nations=[0]*n
    cnt=0
    for i in range(len(nums)):
        if cnt==3:
            break
        if nations[nums[i][0]]!=2:
            nations[nums[i][0]]+=1
            cnt+=1
            print(nums[i][0],nums[i][1])
    return nums
n=int(input())
nums=[ list(map(int, input().split())) for i in range(n)]
 
(sol(n,nums))
cs

나라에 해당하는 인덱스 (LIne3) 생성 lambda를 이용해 정렬
Make Indices for Nations, using lambda sort

반응형

댓글