Greedy Algorithm python

2022. 12. 5. 13:49

공포도 X인 모험가는 반드시 X명 이상으로 구성
입력
- 첫째줄: N
- 둘째줄: N명의 공포도

출력
- 길드 그룹의 최대값

 

 

Greedy Algorithm 

 

 

def main():
    n = int(input())
    group = list(map(int, input().split()))
    group.sort()

    result = 0
    count = 0

    for x in group:
        count += 1
        if count >= x:
            count = 0
            result += 1

    print(result)


if __name__ == "__main__":
    main()

BELATED ARTICLES

more