Submission #1477082


Source Code Expand

import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    int W, H;
    PriorityQueue<Edge> qs;

    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        W = sc.nextInt();
        H = sc.nextInt();
        qs = new PriorityQueue<>((e1, e2) ->
           Long.compare(e1.cost, e2.cost));
        int i;
        long tmp;
        for (i = 0; i < W; i++) {
            tmp = sc.nextLong();
            qs.add(new Edge(i+1, i, tmp, true));
        }
        for (int j = 0; j < H; j++) {
            tmp = sc.nextLong();
            qs.add(new Edge(j+1, j, tmp, false));
        }
    }

    private void solve() {
        int a = H+1;
        int b = W+1;
        long ans = 0L;
        while (!qs.isEmpty()) {
            Edge e = qs.poll();
            if (e.isCol) {
                ans += e.cost * a;
                b--;
            } else {
                ans += e.cost * b;
                a--;
            }
        }
        System.out.println(ans);
    }

    private class Edge {
        boolean isCol;
        int to, from;
        long cost;
        Edge(int to, int from, long c, boolean isCol) {
            this.to = to;
            this.cost = c;
            this.from = from;
            this.isCol = isCol;
        }
    }

}

Submission Info

Submission Time
Task C - Gr-idian MST
User nmjiri
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 1524 Byte
Status AC
Exec Time 837 ms
Memory 102824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 30
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 837 ms 74104 KB
02.txt AC 795 ms 98176 KB
03.txt AC 780 ms 70756 KB
04.txt AC 783 ms 101116 KB
05.txt AC 778 ms 73080 KB
06.txt AC 791 ms 75404 KB
07.txt AC 794 ms 72888 KB
08.txt AC 721 ms 72468 KB
09.txt AC 745 ms 70420 KB
10.txt AC 810 ms 73204 KB
11.txt AC 794 ms 71364 KB
12.txt AC 761 ms 94440 KB
13.txt AC 795 ms 98764 KB
14.txt AC 782 ms 70708 KB
15.txt AC 827 ms 99560 KB
16.txt AC 633 ms 63660 KB
17.txt AC 666 ms 51056 KB
18.txt AC 636 ms 63248 KB
19.txt AC 604 ms 48796 KB
20.txt AC 665 ms 88988 KB
21.txt AC 781 ms 91064 KB
22.txt AC 748 ms 102824 KB
23.txt AC 732 ms 71572 KB
24.txt AC 724 ms 75924 KB
25.txt AC 174 ms 25428 KB
26.txt AC 174 ms 25940 KB
27.txt AC 183 ms 26452 KB
28.txt AC 172 ms 26068 KB
s1.txt AC 164 ms 26708 KB
s2.txt AC 172 ms 26196 KB