[SWEA] 1940 | 가랏! RC카!

Gaanii·2024년 11월 12일

Problem Solving

목록 보기
145/210
post-thumbnail

문제링크


1940 | 가랏! RC카!



풀이과정


명령을 일단 리스트로 입력받자.
그리고 리스트의 0번 인덱스의 값이 1이라면 속력을 입력받은 값만큼 올려주고, 2라면 빼주면 된다.

이때 감속을 해서 속도가 0보다 작아지는 경우는 0으로 설정해준다.


코드


T = int(input())

for tc in range(1, T+1):
    distance = 0
    speed = 0
    N = int(input())
    for _ in range(N):
        command = list(input().split())
        if int(command[0]) == 1:
            speed += int(command[1])
        elif int(command[0]) == 2:
            speed -= int(command[1])
            if speed < 0:
                speed = 0
        distance += speed

    print(f'#{tc} {distance}')


결과


정답

0개의 댓글