[백준] 5800번 성적 통계

거북이·2023년 1월 5일
0

백준[실버5]

목록 보기
52/114
post-thumbnail

💡문제접근

각 클래스별 데이터를 정렬해서 maxmin을 사용해서 가장 높은 점수와 가장 낮은 점수를 구하고 인접한 점수들의 차이를 구해서 점수 차이보다 큰 값을 가진다면 최댓값을 갱신해주는 방식으로 코드를 작성했다.

💡코드(메모리 : 30616KB, 시간 : 40ms)

K = int(input())
Class = []
cnt = 1
for i in range(K):
    Max_Gap = 0
    information = list(map(int, input().split()))
    information = sorted(information[1:])
    Class.append(information)

    max_score = max(Class[i])
    min_score = min(Class[i])
    for t in range(len(information) - 1):
        if abs(information[t] - information[t + 1]) > Max_Gap:
            Max_Gap = abs(information[t] - information[t + 1])
    print("Class", cnt)
    print("Max", str(max_score) + ",", "Min", str(min_score) + ",", "Largest gap", Max_Gap)
    cnt += 1

💡소요시간 : 8m

0개의 댓글