BOJ - 20116 - 상자의 균형

Updated:

import sys

def solution():
    N, L = map(int, sys.stdin.readline().split())
    arr = list(map(int, sys.stdin.readline().split()))

    right = arr[-1]
    count = 1

    for i in range(N-2, -1, -1):
        if arr[i] > arr[i + 1] + L or arr[i] < arr[i + 1] - L:
            print("unstable")
            return

        if right >= arr[i] + L or right <= arr[i] - L:
            print("unstable")
            return

        right = (right * count + arr[i]) / (count + 1)
        count += 1

    print("stable")

solution()

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

Categories:

Updated:

Leave a comment