結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tenten |
提出日時 | 2023-12-11 15:00:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,847 ms / 3,000 ms |
コード長 | 3,080 bytes |
コンパイル時間 | 3,263 ms |
コンパイル使用メモリ | 86,052 KB |
実行使用メモリ | 85,856 KB |
最終ジャッジ日時 | 2024-11-22 10:18:36 |
合計ジャッジ時間 | 44,553 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
37,064 KB |
testcase_01 | AC | 56 ms
37,088 KB |
testcase_02 | AC | 55 ms
37,284 KB |
testcase_03 | AC | 96 ms
38,276 KB |
testcase_04 | AC | 88 ms
38,144 KB |
testcase_05 | AC | 67 ms
37,212 KB |
testcase_06 | AC | 116 ms
40,092 KB |
testcase_07 | AC | 113 ms
40,064 KB |
testcase_08 | AC | 110 ms
40,320 KB |
testcase_09 | AC | 123 ms
40,120 KB |
testcase_10 | AC | 69 ms
37,292 KB |
testcase_11 | AC | 122 ms
40,208 KB |
testcase_12 | AC | 96 ms
38,772 KB |
testcase_13 | AC | 112 ms
39,424 KB |
testcase_14 | AC | 121 ms
40,108 KB |
testcase_15 | AC | 120 ms
40,016 KB |
testcase_16 | AC | 95 ms
38,308 KB |
testcase_17 | AC | 117 ms
39,892 KB |
testcase_18 | AC | 818 ms
66,956 KB |
testcase_19 | AC | 250 ms
44,516 KB |
testcase_20 | AC | 1,068 ms
77,744 KB |
testcase_21 | AC | 876 ms
66,064 KB |
testcase_22 | AC | 675 ms
61,520 KB |
testcase_23 | AC | 584 ms
56,436 KB |
testcase_24 | AC | 314 ms
47,540 KB |
testcase_25 | AC | 877 ms
69,900 KB |
testcase_26 | AC | 745 ms
62,492 KB |
testcase_27 | AC | 903 ms
69,220 KB |
testcase_28 | AC | 224 ms
44,876 KB |
testcase_29 | AC | 782 ms
62,752 KB |
testcase_30 | AC | 467 ms
51,984 KB |
testcase_31 | AC | 1,081 ms
77,808 KB |
testcase_32 | AC | 332 ms
47,648 KB |
testcase_33 | AC | 443 ms
52,180 KB |
testcase_34 | AC | 973 ms
73,644 KB |
testcase_35 | AC | 1,086 ms
77,816 KB |
testcase_36 | AC | 1,049 ms
77,584 KB |
testcase_37 | AC | 629 ms
57,952 KB |
testcase_38 | AC | 1,287 ms
78,744 KB |
testcase_39 | AC | 1,327 ms
78,848 KB |
testcase_40 | AC | 1,287 ms
78,616 KB |
testcase_41 | AC | 1,227 ms
73,552 KB |
testcase_42 | AC | 1,312 ms
78,780 KB |
testcase_43 | AC | 1,225 ms
77,244 KB |
testcase_44 | AC | 1,309 ms
78,976 KB |
testcase_45 | AC | 1,107 ms
68,800 KB |
testcase_46 | AC | 701 ms
56,256 KB |
testcase_47 | AC | 1,320 ms
78,948 KB |
testcase_48 | AC | 1,120 ms
82,280 KB |
testcase_49 | AC | 1,838 ms
85,856 KB |
testcase_50 | AC | 1,795 ms
84,648 KB |
testcase_51 | AC | 1,847 ms
81,024 KB |
testcase_52 | AC | 1,805 ms
80,212 KB |
testcase_53 | AC | 487 ms
50,700 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } TreeSet<Num> nums = new TreeSet<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); nums.add(new Num(i, values[i], x, (values[i] + x) / 2)); } int ans = nums.last().getValue() - nums.first().getValue(); while (!nums.first().isBiggest()) { Num x = nums.pollFirst(); x.add(); nums.add(x); ans = Math.min(ans, nums.last().getValue() - nums.first().getValue()); } System.out.println(ans); } static class Num implements Comparable<Num> { int[] values; int idx = 0; int x; public Num(int x, int[] values) { this.x = x; this.values = values; Arrays.sort(values); } public Num(int x, int a, int b, int c) { this(x, new int[]{a, b, c}); } public int getValue() { return values[idx]; } public int compareTo(Num another) { if (getValue() == another.getValue()) { return x - another.x; } else { return getValue() - another.getValue(); } } public boolean isBiggest() { return idx == 2; } public void add() { idx++; } public String toString() { return getValue() + ":" + x + ":" + idx + ":" + Arrays.toString(values); } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }