Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class Job implements Comparable<Job> {
- long a;
- long b;
- int index;
- public Job(long a, long b, int index) {
- this.a = a;
- this.b = b;
- this.index = index;
- }
- @Override
- public int compareTo(Job that) {
- long thisTime = this.a + Math.max(this.b, that.a) + that.b;
- long thatTime = that.a + Math.max(this.a, that.b) + this.b;
- return Long.compare(thisTime, thatTime);
- }
- @Override
- public String toString() {
- return "(" + a + "," + b + ") - " + index;
- }
- }
- public static void solve(long[] a, long[] b, int[] order) throws IOException {
- long[][] start = new long[2][a.length];
- int prev = -1;
- for (int i : order) {
- if (prev == -1) {
- start[0][i] = 0;
- start[1][i] = a[i];
- } else {
- start[0][i] = start[0][prev] + a[prev];
- start[1][i] = Math.max(start[1][prev] + b[prev], start[0][i] + a[i]);
- }
- prev = i;
- }
- long time = start[1][prev] + b[prev];
- bw.write(time + "n");
- for (int i = 0; i < start.length; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < start[0].length; ++j)
- sb.append(start[i][j] + " ");
- bw.write(sb.toString().trim() + "n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement