[swexpert] 1940. 가랏! RC카! (D2, JAVA)

728x90
반응형

 

import java.util.Scanner;

public class Solution {
	static int t,n;
	static int x,speed;
	static int answer;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		t=sc.nextInt();
		for (int tc = 1; tc <=t; tc++) {
			answer=0;
			speed=0;
			n=sc.nextInt();
			for (int i = 0; i < n; i++) {
				x=sc.nextInt();
				if(x==1) {
					speed+=sc.nextInt();
				}else if(x==2) {
					speed-=sc.nextInt();
					if(speed<0)speed=0;
				}
				answer+=speed;
			}
			
			System.out.printf("#%d %d\n",tc,answer);
		}
	}
}
728x90
반응형
TAGS.

Comments