https://www.acmicpc.net/problem/1276
문제
풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
static class Platform implements Comparable<Platform> {
int y, x1, x2;
public Platform(int y, int x1, int x2) {
this.y = y;
this.x1 = x1;
this.x2 = x2;
}
@Override
public int compareTo(Platform o) {
return this.y - o.y;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int n = Integer.valueOf(st.nextToken());
PriorityQueue<Platform> pq = new PriorityQueue<>();
for(int i=0 ; i<n ; i++) {
st = new StringTokenizer(br.readLine(), " ");
int y = Integer.valueOf(st.nextToken());
int x1 = Integer.valueOf(st.nextToken());
int x2 = Integer.valueOf(st.nextToken());
pq.add(new Platform(y, x1, x2));
}
int ans=0;
int[] lenList = new int[10001];
while(!pq.isEmpty()) {
Platform p = pq.poll();
for(int i=p.x1; i<p.x2; i++) {
if(i ==p.x1 || i==p.x2 - 1) {
ans += p.y - lenList[i];
}
lenList[i]=p.y;
}
}
System.out.println(ans);
}
}
후기
오랜만에 올리네요.. 그래서 거의 다 까먹어버린.. 반성 중..
잔디 심기 챌린지에 참여하게 되어서 다시 시작합니다!
100일 동안 화이팅~!
'코딩테스트' 카테고리의 다른 글
[백준] 1946번 '신입 사원' - Java (0) | 2024.08.07 |
---|---|
[백준] 1581번 '락스타 락동호' - Java (0) | 2024.08.06 |
[프로그래머스] 피로도 - Java (0) | 2024.02.01 |
[프로그래머스] 신고 결과 받기 - Python (0) | 2024.01.13 |
[백준] 1365번 '꼬인 전깃줄' - Python (1) | 2023.12.29 |