The Product Manager (PM) has a lot of good idea, which needs to be realized by the programmer. Now there are n pm, and at some point you'll come up with an idea, each idea has a time, time, and priority level. For a PM, the idea that most want to realize is first to consider the high priority, the same case priority time is the smallest, but also the same case to choose the first to come up with, no PM will put forward two ideas at the same time.
At the same time, with M programmers, each programmer is free to look at an idea that each PM has not yet executed and wants to accomplish, and then pick out a thought that is the smallest of the time needed, and select the smallest PM number if the time is the same. This is not repeated until the idea is complete. If you have multiple programmers who are idle at the same time, they will see the idea in turn.
Find the time for each idea implementation.
Enter the first line of three numbers n, M, p, respectively, representing n a pm,m programmer, p idea. Then there are P lines, each with 4 digits, the PM serial number, the time of submission, the priority level, and the time required. The output P line, respectively, represents the point in time for each idea implementation.
Enter a description:
Enter the first line of three numbers n, M, p, respectively, representing n a pm,m programmer, p idea. Then there are P lines, each with 4 digits, the PM serial number, the time of submission, the priority level, and the time required. All data ranges [1, 3000].
Output Description:
The output P line, respectively, represents the point in time for each idea implementation.
Example 1
input
2 2 5 1 1 1 2 1 2 1 1 1 3 2 2 2 1 1 2 2 3 5-
5
Output
3
4
5
3
9
The Java AC code is as follows:
Import java.util.*;
public class main{private static Scanner sc = new Scanner (system.in);
Static class Ideatask {int pmseq;
int raisetime;
int prio;
int timecost;
int endtime;
Public ideatask (int pmseq, int raisetime, int prio, int timecost) {this.pmseq = Pmseq;
This.raisetime = Raisetime;
This.prio = Prio;
This.timecost = Timecost; } static class PM {priorityqueue<ideatask> PQ = new Priorityqueue<> (comparator.comparingi
NT (x-> x.raisetime)); Given the time the programmer started working, find the task that the PM most wanted to accomplish ideatask mostdesiredtask (int starttime) {priorityqueue<ideatask> P
Q2 = new Priorityqueue<> ((x, y)-> {if (X.prio!= Y.prio) return Y.prio-x.prio;
else {if (x.timecost!= y.timecost) return x.timecost-y.timecost; else return X.raisetime-y.raisetIme
}
});
while (Pq.peek ()!= null && pq.peek (). Raisetime <= starttime) {Pq2.offer (Pq.poll ()); } ideatask Mostdesiredtask = (Pq2.isempty ())?
Pq.poll (): Pq2.poll ();
while (!pq2.isempty ()) {Pq.offer (Pq2.poll ());
return mostdesiredtask;
} static class Programmer {int nextworktime;//the next time it can work public programmer (int nextworktime) {
This.nextworktime = Nextworktime;
}//From multiple PM Most wanted to complete idea, choose one of the PM want to complete idea private static Ideatask Selecttask (pm[] PMS, int worktime) { Priorityqueue<ideatask> PQ = new Priorityqueue<> ((x, y)-> {if (x.raisetime = = Y.raisetime | | (X.raisetime <= worktime && y.raisetime <=))
{if (x.timecost!= y.timecost) return x.timecost-y.timecost; else return X.PMSEQ- Y.pmseq;
} if (X.raisetime > Worktime && y.raisetime > Worktime) return x.raisetime-y.raisetime;
if (X.raisetime > Worktime) return 1;
if (Y.raisetime > Worktime) return-1;
return 0;
});
for (int i = 1; i < pms.length i++) {pm PM = pms[i];
Ideatask desiredtask = Pm.mostdesiredtask (worktime);
if (desiredtask!= null) pq.offer (desiredtask);
} ideatask task = Pq.poll ();
while (!pq.isempty ()) {Ideatask tmp = Pq.poll ();
Pms[tmp.pmseq].pq.offer (TMP);
} return task; private static list<ideatask> gettasks (int tasknum) {list<ideatask> tasks = new Linkedlist<
;> ();
while (tasknum--> 0) {tasks.add (New Ideatask (Sc.nextint (), Sc.nextint (), Sc.nextint (), Sc.nextint ()));
return tasks; } privateStatic pm[] INITPM (int n, list<ideatask> tasks) {pm[] PMs = new Pm[n + 1];
for (int i = 1; I <= n; i++) pms[i] = new PM ();
for (Ideatask task:tasks) {pms[task.pmseq].pq.offer (Task);
return to PMS;
public static void Main (string[] args) {int n = sc.nextint (), M = Sc.nextint (), p = Sc.nextint ();
list<ideatask> tasks = Gettasks (p);
pm[] PMs = INITPM (n, tasks); priorityqueue<programmer> LOSERSPQ = new Priorityqueue<> (comparator.comparingint (x-> x.nextWorkTime)
);
for (int i = 0; i < m i++) Loserspq.offer (new programmer (0));
while (true) {programmer loser = Loserspq.poll ();
Ideatask task = Selecttask (PMS, Loser.nextworktime);
if (task = null) break;
Task.endtime = Integer.max (Task.raisetime, loser.nextworktime) + task.timecost;
Loser.nextworktime = Task.endtime; LoserspQ.offer (loser);
for (Ideatask task:tasks) {System.out.println (task.endtime); }
}
}