|
| 1 | +import java.io.*; |
| 2 | +import java.util.*; |
| 3 | + |
| 4 | +public class MinimizingLateness { |
| 5 | + |
| 6 | + private static class Schedule { // Schedule class |
| 7 | + int t = 0; // Time required for the operation to be performed |
| 8 | + int d = 0; // Time the job should be completed |
| 9 | + int s = 0; // Start time of the task |
| 10 | + int f = 0; // End time of the operation |
| 11 | + |
| 12 | + public Schedule(int t, int d) { |
| 13 | + this.t = t; |
| 14 | + this.d = d; |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + public static void main(String[] args) throws IOException { |
| 19 | + // TODO Auto-generated method stub |
| 20 | + StringTokenizer token; |
| 21 | + |
| 22 | + String ch; |
| 23 | + BufferedReader in = new BufferedReader(new FileReader("input.txt")); |
| 24 | + int indexCount; // size of array index |
| 25 | + ch = in.readLine(); |
| 26 | + indexCount = Integer.parseInt(ch); // The first line specifies the size of the operation (= the size of the array) |
| 27 | + System.out.println("Input Data : "); |
| 28 | + System.out.println(indexCount); // number of operations |
| 29 | + Schedule array[] = new Schedule[indexCount]; // Create an array to hold the operation |
| 30 | + int i = 0; |
| 31 | + while ((ch = in.readLine()) != null) { |
| 32 | + token = new StringTokenizer(ch, " "); |
| 33 | + // Include the time required for the operation to be performed in the array and the time it should be completed. |
| 34 | + array[i] = new Schedule(Integer.parseInt(token.nextToken()), Integer.parseInt(token.nextToken())); |
| 35 | + i++; // 다음 인덱스 |
| 36 | + System.out.println(array[i - 1].t + " " + array[i - 1].d); |
| 37 | + } |
| 38 | + |
| 39 | + int tryTime = 0; // Total time worked |
| 40 | + int lateness = 0; // Lateness |
| 41 | + for (int j = 0; j < indexCount - 1; j++) { |
| 42 | + array[j].s = tryTime; // Start time of the task |
| 43 | + array[j].f = tryTime + array[j].t; // Time finished |
| 44 | + tryTime = tryTime + array[j].t; // Add total work time |
| 45 | + // Lateness |
| 46 | + lateness = lateness + Math.max(0, tryTime - array[j].d); |
| 47 | + } |
| 48 | + System.out.println(); |
| 49 | + System.out.println("Output Data : "); |
| 50 | + System.out.println(lateness); |
| 51 | + } |
| 52 | +} |
0 commit comments