Link
Today
Total
12-23 08:10
Archives
관리 메뉴

초보개발자 긍.응.성

[Java] 8998. 세운이는 내일 할거야 본문

코딩테스트/SW Expert Academy

[Java] 8998. 세운이는 내일 할거야

긍.응.성 2020. 3. 23. 17:04
반응형

D3-8998. 세운이는 내일 할거야

 

문제출처: https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW6GMWCqLdkDFAVX&

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

날짜순으로 뒤에서 부터 가능한지 검사

 

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


class Solution {
	

	static PriorityQueue<int[]> assignments = new PriorityQueue<>(new Comparator<int[]>() {
		@Override
		public int compare(int[] i1, int[] i2) {
			return i2[1] - i1[1];
		}
	});
	
	public static void main(String args[]) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());

		for (int test_case = 1; test_case <= T; test_case++) {
			assignments.clear();
		
			int N = Integer.parseInt(br.readLine());
			for (int i = 0; i < N; i++) {
				st = new StringTokenizer(br.readLine());
				assignments.add(new int[] {Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())});
			}
			
			int assignment[] = assignments.poll();
			int startTime = assignment[1] - assignment[0];
			while (!assignments.isEmpty()) {
				assignment = assignments.poll();
				if (startTime < assignment[1])
					startTime -= assignment[0];
				else
					startTime = assignment[1] - assignment[0];
			}
			bw.write("#" + test_case + " " + startTime + "\n");
		}

		br.close();
		bw.flush();
		bw.close();
	}
}
반응형
Comments