#문제
https://www.acmicpc.net/problem/21773
#소스코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class BOJ21773 {
public static class Work implements Comparable<Work>{
int id;
int time;
int priority;
public Work(int id, int time, int priority){
this.id =id;
this.time = time;
this.priority = priority;
}
@Override
public int compareTo(Work w){
int rs = w.priority - this.priority;
if(rs == 0) rs = this.id - w.id;
return rs;
}
}
public static int T, n;
public static PriorityQueue<Work> que;
public static void input() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
T = Integer.parseInt(st.nextToken());
n = Integer.parseInt(st.nextToken());
que = new PriorityQueue<Work>();
for(int i = 0; i < n; i++){
st = new StringTokenizer(br.readLine());
que.offer(new Work(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
}
public static void main(String[] args) throws Exception{
input();
StringBuilder sb = new StringBuilder();
int curTime = 0;
while(!que.isEmpty()){
if(++curTime > T) break;
Work w = que.poll();
sb.append(w.id + "\n");
w.time--;
w.priority--;
if(w.time > 0) que.offer(w);
}
System.out.println(sb.toString());
}
}
'💡Problem Solving > BOJ' 카테고리의 다른 글
[BOJ 15900] 나무 탈출 (Java) (0) | 2021.10.21 |
---|---|
[BOJ 2056] 작업 (Java) (0) | 2021.10.20 |
[BOJ 21772] 가희의 고구마 먹방 (Java) (0) | 2021.10.19 |
[BOJ 22232] 가희와 파일 탐색기 (Java) (0) | 2021.10.18 |
[BOJ 1874] 스택 수열 (Java) (0) | 2021.10.17 |