Submission #1441095
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 ((W - pPtr + 1) * q[qPtr] <= (H - qPtr + 1) * 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 | 3718 Byte |
Status | WA |
Exec Time | 215 ms |
Memory | 25724 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||||
Status |
|
|
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 | 170 ms | 21820 KB |
02.txt | WA | 164 ms | 21916 KB |
03.txt | WA | 172 ms | 24912 KB |
04.txt | WA | 182 ms | 21028 KB |
05.txt | WA | 191 ms | 21052 KB |
06.txt | WA | 160 ms | 24776 KB |
07.txt | WA | 173 ms | 25724 KB |
08.txt | WA | 196 ms | 23096 KB |
09.txt | WA | 215 ms | 22788 KB |
10.txt | WA | 200 ms | 22996 KB |
11.txt | WA | 207 ms | 24384 KB |
12.txt | WA | 137 ms | 23128 KB |
13.txt | WA | 129 ms | 21728 KB |
14.txt | WA | 164 ms | 20580 KB |
15.txt | WA | 168 ms | 24372 KB |
16.txt | WA | 168 ms | 23384 KB |
17.txt | WA | 126 ms | 22368 KB |
18.txt | WA | 132 ms | 19940 KB |
19.txt | WA | 121 ms | 23084 KB |
20.txt | AC | 120 ms | 23068 KB |
21.txt | WA | 181 ms | 24676 KB |
22.txt | WA | 141 ms | 20360 KB |
23.txt | WA | 121 ms | 20880 KB |
24.txt | WA | 129 ms | 20032 KB |
25.txt | AC | 67 ms | 20180 KB |
26.txt | AC | 67 ms | 20820 KB |
27.txt | AC | 67 ms | 21076 KB |
28.txt | AC | 75 ms | 19284 KB |
s1.txt | AC | 67 ms | 21076 KB |
s2.txt | AC | 67 ms | 20948 KB |