Submission #1441103


Source Code Expand


import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int W = sc.nextInt();
    int H = sc.nextInt();

    int[] p = sc.nextIntList(W);
    int[] q = sc.nextIntList(H);
    
    Arrays.sort(p);
    Arrays.sort(q);
    
    int pPtr = 0;
    int qPtr = 0;
    
    long cost = 0;
    while (W > pPtr || H > qPtr) {
      if (W == pPtr) {
        cost += q[qPtr ++];
      } else if (H == qPtr) {
        cost += p[pPtr ++];
      } else if (q[qPtr] <= p[pPtr]) {
        cost += (W - pPtr + 1) * q[qPtr ++];
      } else {
        cost += (H - qPtr + 1) * p[pPtr ++];
      }
    }
    System.out.println(cost);
  }
}


class FastScanner {
  public static String debug = null;

  private final InputStream in = System.in;
  private int ptr = 0;
  private int buflen = 0;
  private byte[] buffer = new byte[1024];
  private boolean eos = false;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        if (debug != null) {
          buflen = debug.length();
          buffer = debug.getBytes();
          debug = "";
          eos = true;
        } else {
          buflen = in.read(buffer);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen < 0) {
        eos = true;
        return false;
      } else if (buflen == 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte())
      return buffer[ptr++];
    else
      return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
      ptr++;
  }

  public boolean isEOS() {
    return this.eos;
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
      throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
      throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    return (int) nextLong();
  }

  public long[] nextLongList(int n) {
    return nextLongTable(1, n)[0];
  }

  public int[] nextIntList(int n) {
    return nextIntTable(1, n)[0];
  }

  public long[][] nextLongTable(int n, int m) {
    long[][] ret = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextLong();
      }
    }
    return ret;
  }

  public int[][] nextIntTable(int n, int m) {
    int[][] ret = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ret[i][j] = nextInt();
      }
    }
    return ret;
  }
}

Submission Info

Submission Time
Task C - Gr-idian MST
User hiromi_ayase
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 3686 Byte
Status WA
Exec Time 194 ms
Memory 24900 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 9
WA × 21
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 WA 162 ms 19656 KB
02.txt WA 159 ms 23448 KB
03.txt WA 159 ms 17516 KB
04.txt WA 161 ms 21072 KB
05.txt WA 159 ms 23516 KB
06.txt WA 159 ms 23024 KB
07.txt WA 151 ms 21180 KB
08.txt WA 161 ms 22756 KB
09.txt WA 184 ms 21816 KB
10.txt WA 164 ms 21492 KB
11.txt WA 177 ms 24568 KB
12.txt WA 143 ms 21532 KB
13.txt WA 113 ms 24644 KB
14.txt WA 194 ms 24576 KB
15.txt WA 161 ms 22464 KB
16.txt WA 171 ms 24152 KB
17.txt WA 122 ms 22452 KB
18.txt WA 125 ms 22108 KB
19.txt WA 125 ms 20392 KB
20.txt AC 117 ms 21732 KB
21.txt AC 157 ms 21188 KB
22.txt AC 144 ms 21500 KB
23.txt WA 120 ms 24900 KB
24.txt WA 125 ms 22560 KB
25.txt AC 67 ms 19156 KB
26.txt AC 66 ms 17876 KB
27.txt AC 67 ms 19156 KB
28.txt AC 67 ms 21076 KB
s1.txt AC 68 ms 18644 KB
s2.txt AC 67 ms 21076 KB