結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tenten |
提出日時 | 2023-12-11 15:00:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,738 ms / 3,000 ms |
コード長 | 3,080 bytes |
コンパイル時間 | 3,036 ms |
コンパイル使用メモリ | 93,296 KB |
実行使用メモリ | 84,876 KB |
最終ジャッジ日時 | 2024-05-02 01:08:53 |
合計ジャッジ時間 | 41,205 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,120 KB |
testcase_01 | AC | 53 ms
37,176 KB |
testcase_02 | AC | 53 ms
37,052 KB |
testcase_03 | AC | 83 ms
38,384 KB |
testcase_04 | AC | 86 ms
38,504 KB |
testcase_05 | AC | 74 ms
37,628 KB |
testcase_06 | AC | 108 ms
39,852 KB |
testcase_07 | AC | 116 ms
40,276 KB |
testcase_08 | AC | 116 ms
40,188 KB |
testcase_09 | AC | 113 ms
40,112 KB |
testcase_10 | AC | 66 ms
37,668 KB |
testcase_11 | AC | 118 ms
40,432 KB |
testcase_12 | AC | 93 ms
38,876 KB |
testcase_13 | AC | 110 ms
39,840 KB |
testcase_14 | AC | 115 ms
40,188 KB |
testcase_15 | AC | 116 ms
40,252 KB |
testcase_16 | AC | 93 ms
38,608 KB |
testcase_17 | AC | 114 ms
40,272 KB |
testcase_18 | AC | 756 ms
66,324 KB |
testcase_19 | AC | 235 ms
45,812 KB |
testcase_20 | AC | 874 ms
73,532 KB |
testcase_21 | AC | 828 ms
64,812 KB |
testcase_22 | AC | 614 ms
61,900 KB |
testcase_23 | AC | 497 ms
55,624 KB |
testcase_24 | AC | 282 ms
47,696 KB |
testcase_25 | AC | 891 ms
70,168 KB |
testcase_26 | AC | 774 ms
62,836 KB |
testcase_27 | AC | 797 ms
70,044 KB |
testcase_28 | AC | 212 ms
45,116 KB |
testcase_29 | AC | 783 ms
62,700 KB |
testcase_30 | AC | 459 ms
52,016 KB |
testcase_31 | AC | 959 ms
73,480 KB |
testcase_32 | AC | 308 ms
47,224 KB |
testcase_33 | AC | 424 ms
52,132 KB |
testcase_34 | AC | 936 ms
77,980 KB |
testcase_35 | AC | 1,053 ms
77,584 KB |
testcase_36 | AC | 1,026 ms
77,376 KB |
testcase_37 | AC | 618 ms
57,964 KB |
testcase_38 | AC | 1,260 ms
78,636 KB |
testcase_39 | AC | 1,191 ms
78,476 KB |
testcase_40 | AC | 1,215 ms
78,580 KB |
testcase_41 | AC | 1,165 ms
73,356 KB |
testcase_42 | AC | 1,143 ms
79,332 KB |
testcase_43 | AC | 1,064 ms
77,096 KB |
testcase_44 | AC | 1,188 ms
78,860 KB |
testcase_45 | AC | 1,005 ms
69,004 KB |
testcase_46 | AC | 673 ms
56,288 KB |
testcase_47 | AC | 1,176 ms
78,704 KB |
testcase_48 | AC | 983 ms
81,800 KB |
testcase_49 | AC | 1,738 ms
82,636 KB |
testcase_50 | AC | 1,728 ms
84,484 KB |
testcase_51 | AC | 1,696 ms
84,876 KB |
testcase_52 | AC | 1,647 ms
84,508 KB |
testcase_53 | AC | 433 ms
50,864 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(); } }