import java.time.Duration;
import java.time.LocalTime;
import java.util.*;
public class Main {
public static void main
(String[] args
) {
LinkedList<Process> list = new LinkedList<>();
LinkedList<Process> copyList = new LinkedList<>();
Scanner sc
= new Scanner
(System.
in);
int n = sc.nextInt();
long timeSlice = sc.nextLong(); //to millis
for (int i = 0; i < n; i++) {
Process process
= new Process(sc.
next(), sc.
nextDouble(), sc.
nextDouble()); //to seconds
list.add(process);
copyList.add(process);
}
processRoundRobin(copyList, timeSlice);
list) {
process.completeData();
}
String[] averages
= getAverages
(list
);
System.
out.
println("ART: " + averages
[0] + ", AWT: " + averages
[1]);
}
static String[] getAverages
(LinkedList
<Process
> list
){
double ART = 0, AWT = 0;
list) {
AWT += p.WT;
ART += p.RT;
}
ART /= list.size();
AWT /= list.size();
}
static void processRoundRobin(LinkedList<Process> list, long timeSlice){
LinkedList<Process> queue = new LinkedList<>();
LocalTime startTime = LocalTime.now();
while (list.size() != 0){
if(list.getFirst().AT <= Duration.between(startTime, LocalTime.now()).toMillis() / 1000.0){
queue.add(process);
}
}
});
arriveTimeCheckThread.start();
while (list.size() !=0 || queue.size() != 0){
System.
out.
print("");// Warning!: don't erase this line, or it will never exit the loop
if(queue.size() != 0){
process.process(timeSlice);
if(process.remainedTime > 0){
queue.add(process);
}else {
process.FT = Duration.between(startTime, LocalTime.now()).toMillis() / 1000.0;
}
}
}
});
processThread.start();
try {
arriveTimeCheckThread.join();
processThread.join();
}
}
double AT, CBT, FT, RT, WT;
double remainedTime;
@Override
return "Process{" +
"name='" + name + '\'' +
", AT=" + AT +
", CBT=" + CBT +
", FT=" + String.
format("%.03f", FT
) +
", RT=" + String.
format("%.03f", RT
) +
", WT=" + String.
format("%.03f", WT
) +
'}';
}
this.name = name;
this.AT = AT;
this.CBT = CBT;
this.remainedTime = CBT;
}
void process(long timeSlice){
LocalTime startTime = LocalTime.now();
try {
// System.out.println("timeSlice: " + timeSlice);
}
LocalTime now = LocalTime.now();
long processTime = Duration.between(startTime, now).toMillis();
// System.out.println(name + " process time:" + processTime);
remainedTime -= processTime / 1000.0;
// System.out.println(this + " remainedTime:" + remainedTime);
}
void completeData(){
RT = FT - AT;
WT = RT - CBT;
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}