結果

問題 No.2248 max(C)-min(C)
ユーザー tentententen
提出日時 2023-07-26 16:55:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,810 ms / 3,000 ms
コード長 3,179 bytes
コンパイル時間 2,992 ms
コンパイル使用メモリ 85,428 KB
実行使用メモリ 94,704 KB
最終ジャッジ日時 2024-04-14 06:31:54
合計ジャッジ時間 44,171 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
50,464 KB
testcase_01 AC 58 ms
50,496 KB
testcase_02 AC 59 ms
50,164 KB
testcase_03 AC 99 ms
51,568 KB
testcase_04 AC 84 ms
51,628 KB
testcase_05 AC 84 ms
51,432 KB
testcase_06 AC 119 ms
52,936 KB
testcase_07 AC 107 ms
52,844 KB
testcase_08 AC 122 ms
52,808 KB
testcase_09 AC 118 ms
52,804 KB
testcase_10 AC 82 ms
51,440 KB
testcase_11 AC 126 ms
52,920 KB
testcase_12 AC 102 ms
51,548 KB
testcase_13 AC 112 ms
52,084 KB
testcase_14 AC 110 ms
52,960 KB
testcase_15 AC 113 ms
52,896 KB
testcase_16 AC 99 ms
51,600 KB
testcase_17 AC 120 ms
52,904 KB
testcase_18 AC 830 ms
77,572 KB
testcase_19 AC 237 ms
56,260 KB
testcase_20 AC 1,054 ms
89,316 KB
testcase_21 AC 911 ms
78,496 KB
testcase_22 AC 702 ms
73,852 KB
testcase_23 AC 577 ms
66,904 KB
testcase_24 AC 300 ms
58,620 KB
testcase_25 AC 890 ms
81,620 KB
testcase_26 AC 771 ms
72,452 KB
testcase_27 AC 823 ms
80,824 KB
testcase_28 AC 221 ms
55,944 KB
testcase_29 AC 774 ms
72,656 KB
testcase_30 AC 448 ms
62,412 KB
testcase_31 AC 1,045 ms
89,316 KB
testcase_32 AC 318 ms
59,184 KB
testcase_33 AC 425 ms
62,348 KB
testcase_34 AC 1,085 ms
89,568 KB
testcase_35 AC 926 ms
75,560 KB
testcase_36 AC 1,055 ms
89,200 KB
testcase_37 AC 617 ms
69,860 KB
testcase_38 AC 1,299 ms
90,784 KB
testcase_39 AC 1,252 ms
91,168 KB
testcase_40 AC 1,303 ms
91,144 KB
testcase_41 AC 1,108 ms
85,008 KB
testcase_42 AC 1,264 ms
90,784 KB
testcase_43 AC 1,169 ms
88,700 KB
testcase_44 AC 1,291 ms
91,156 KB
testcase_45 AC 1,041 ms
78,256 KB
testcase_46 AC 729 ms
66,036 KB
testcase_47 AC 1,308 ms
91,032 KB
testcase_48 AC 927 ms
91,272 KB
testcase_49 AC 1,721 ms
90,888 KB
testcase_50 AC 1,724 ms
90,468 KB
testcase_51 AC 1,810 ms
94,704 KB
testcase_52 AC 1,681 ms
89,644 KB
testcase_53 AC 482 ms
62,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] tmp = new int[n];
        for (int i = 0; i < n; i++) {
            tmp[i] = sc.nextInt();
        }
        TreeSet<Num> all = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            all.add(new Num(i, x, tmp[i], (x + tmp[i]) / 2));
        }
        int ans = Integer.MAX_VALUE;
        while (true) {
            ans = Math.min(ans, all.last().value() - all.first().value());
            Num x = all.pollFirst();
            x.add();
            if (!x.enable()) {
                break;
            }
            all.add(x);
        }
        System.out.println(ans);
    }
    
    static class Num implements Comparable<Num> {
        int idx;
        int[] values;
        int current;
        
        public Num(int idx, int a, int b, int c) {
            this.idx = idx;
            values = new int[]{a, b, c};
            Arrays.sort(values);
            current = 0;
        }
        
        public int value() {
            return values[current];
        }
        
        public void add() {
            current++;
        }
        
        public boolean enable() {
            return current < values.length;
        }
        
        public int compareTo(Num another) {
            if (value() == another.value()) {
                return idx - another.idx;
            } else {
                return value() - another.value();
            }
        }
        
        public boolean equals(Object o) {
            return hashCode() == o.hashCode();
        }
        
        public String toString() {
            return String.valueOf(value());
        }
        
        public int hashCode() {
            return idx;
        }
        
        
    }
}
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();
    }
    
}
0