Submission #301683

#TimeUsernameProblemLanguageResultExecution timeMemory
301683llaki카니발 티켓 (IOI20_tickets)Java
27 / 100
835 ms79104 KiB

import java.util.Arrays;

public class tickets {
    private class TicketsWithColors {
        int color;
        int[] val;
        int from;
        int to;

        TicketsWithColors(int color, int[] val) {
            this.color = color;
            this.val = val;
            this.from = 0;
            this.to = val.length - 1;
        }
    }

    long find_maximum(int k, int[][] x) {
        int n = x.length;
        int m = x[0].length;
        int[][] answer = new int[n][m];
        TicketsWithColors[] t = new TicketsWithColors[n];
        for (int i = 0; i < n; i++) {
            t[i] = new TicketsWithColors(i, x[i]);
        }
        long ans = 0;
        for (int i = 0; i < n; i++) Arrays.fill(answer[i], -1);
        for (int a = 0; a < k; a++) {
            Arrays.sort(t, (t1, t2) ->
                    t1.val[t1.from] + t1.val[t1.to] - t2.val[t2.from] - t2.val[t2.to]);
            for (int i = 0; i < n; i++) {
                int col = t[i].color;
                if (i < n / 2) {
                    answer[col][t[i].from] = 0;
                    ans -= t[i].val[t[i].from];
                    t[i].from++;
                } else {
                    answer[col][t[i].to] = 0;
                    ans += t[i].val[t[i].to];
                    t[i].to--;
                }
            }
        }
        grader.allocate_tickets(answer);
        return ans;
    }


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...