package com.thealgorithms.minimizinglateness;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class MinimizingLateness {
private static class Schedule {
int t = 0;
int d = 0;
public Schedule(int t, int d) {
this.t = t;
this.d = d;
}
}
public static void main(String[] args) throws IOException {
StringTokenizer token;
BufferedReader in = new BufferedReader(new FileReader("MinimizingLateness/lateness_data.txt"));
String ch = in.readLine();
if (ch == null || ch.isEmpty()) {
in.close();
return;
}
int indexCount = Integer.parseInt(ch);
System.out.println("Input Data : ");
System.out.println(indexCount);
Schedule[] array = new Schedule[indexCount];
int i = 0;
while ((ch = in.readLine()) != null) {
token = new StringTokenizer(ch, " ");
array[i] = new Schedule(Integer.parseInt(token.nextToken()), Integer.parseInt(token.nextToken()));
i++;
System.out.println(array[i - 1].t + " " + array[i - 1].d);
}
int tryTime = 0;
int lateness = 0;
for (int j = 0; j < indexCount - 1; j++) {
tryTime = tryTime + array[j].t;
lateness = lateness + Math.max(0, tryTime - array[j].d);
}
System.out.println();
System.out.println("Output Data : ");
System.out.println(lateness);
in.close();
}
}