Problem Solving/Baekjoon
[백준] 13676 Escultura a Laser - Data Structure / Java
graycode
2025. 9. 8. 14:51
• 문제 링크
https://www.acmicpc.net/problem/13676
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
Stack<Integer> stk = new Stack<>();
int a;
while ((a = read()) != 0) {
int c = read(), i = read(), sum = a - stk.push(i);
while (c-- > 1) if ((i = stk.pop() - stk.push(read())) > 0) sum += i;
sb.append(sum).append('\n');
}
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}