본문 바로가기
코딩테스트

[백준] 1276번 'PLATFORME' - Java

by CuckooBird 2024. 8. 5.

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일 동안 화이팅~!