File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class boj21773 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+ static StringTokenizer st;
9+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
10+ static int nextInt() {return Integer . parseInt(st. nextToken());}
11+
12+ public static void main(String [] args) throws Exception {
13+ nextLine();
14+ int T = nextInt();
15+ int n = nextInt();
16+ PriorityQueue<Process > pq = new PriorityQueue<> ();
17+ for (int i = 0 ; i < n; i++ ) {
18+ nextLine();
19+ int a = nextInt();
20+ int b = nextInt();
21+ int c = nextInt();
22+ pq. add(new Process (a, b, c));
23+ }
24+
25+ for (int i = 0 ; i < T ; i++ ) {
26+ if (pq. isEmpty()) break ;
27+ Process process = pq. poll();
28+ bw. write(process. id + " \n " );
29+
30+ process. time -= 1 ;
31+ if (process. time > 0 ) {
32+ process. level -= 1 ;
33+ pq. add(process);
34+ }
35+ }
36+ bw. flush();
37+ }
38+
39+ static class Process implements Comparable<Process > {
40+ int id;
41+ int time;
42+ int level;
43+
44+ public Process (int id , int time , int level ) {
45+ this . id = id;
46+ this . time = time;
47+ this . level = level;
48+ }
49+ @Override
50+ public int compareTo (Process o ) {
51+ if (level == o. level)
52+ return id - o. id;
53+ return o. level - level;
54+ }
55+ }
56+ }
57+ ```
You can’t perform that action at this time.
0 commit comments