SWEA_D2_1940
π [D2_1940] κ°λ! RCμΉ΄!
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution{
static StringTokenizer st;
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
// ν
μ€νΈμΌμ΄μ€
int tc = Integer.parseInt(br.readLine());
for(int T = 1; T<=tc; T++){
sb.append("#").append(T).append(" ");
// μ΄λν 거리
int res = 0;
// μ
λ ₯ κ°μ
int N = Integer.parseInt(br.readLine());
// μλ
int speed = 0;
for(int i=0;i<N;i++){
st = new StringTokenizer(br.readLine(), " ");
int command = Integer.parseInt(st.nextToken());
switch (command){
case 0:
break;
case 1:
speed += Integer.parseInt(st.nextToken());
break;
case 2:
int temp = Integer.parseInt(st.nextToken());
if(speed<temp){
speed = 0;
}
else {
speed -= temp;
}
break;
}
res += speed;
}
sb.append(res).append("\n");
}
System.out.println(sb);
}
}
π€ λμ μκ°
μ²μμ λ¬Έμ μ΄ν΄λ₯Ό μ λͺ»νλ€.. γ
γ
γ
μ’ μ΄μ..?
μ΅μ’
μ΄ν΄ν κ²μ 0 μ΄λ©΄ μλλ₯Ό μ μ§, 1μ΄λ©΄ κΈ°μ‘΄ μλμλ€κ° κ°μλλ₯Ό λνκ³ 2λ©΄ κΈ°μ‘΄ μλμλ€κ° κ°μλλ₯Ό λΉΌλ κ²μ΄λ€.
μ¬λλ€ λ§λ‘λ μΆμ μλ λ¬Όμλͺ»μ΄λ€ μ΄λ¬λλ° γ
γ
γ
κ·Έλμ μ΄ν΄κ° λ νλ€μλ κ² κ°κΈ°λ νλ€
μ½κ° ν μΈμμ΄ μλ λ¬Έμ μΈμμμ μ΄ν΄λ₯Ό νμ΄μΌ νλλ°.. γ
γ