結果

問題 No.1597 Matrix Sort
ユーザー tentententen
提出日時 2021-07-14 09:15:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 625 ms / 1,500 ms
コード長 1,995 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 74,372 KB
実行使用メモリ 63,196 KB
最終ジャッジ日時 2023-09-16 06:37:34
合計ジャッジ時間 15,793 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,452 KB
testcase_01 AC 46 ms
49,468 KB
testcase_02 AC 46 ms
49,348 KB
testcase_03 AC 526 ms
59,960 KB
testcase_04 AC 555 ms
60,920 KB
testcase_05 AC 602 ms
61,756 KB
testcase_06 AC 625 ms
61,732 KB
testcase_07 AC 607 ms
61,368 KB
testcase_08 AC 503 ms
62,220 KB
testcase_09 AC 522 ms
62,732 KB
testcase_10 AC 295 ms
56,784 KB
testcase_11 AC 397 ms
63,196 KB
testcase_12 AC 424 ms
59,532 KB
testcase_13 AC 492 ms
59,864 KB
testcase_14 AC 503 ms
59,044 KB
testcase_15 AC 366 ms
59,596 KB
testcase_16 AC 446 ms
60,000 KB
testcase_17 AC 496 ms
63,040 KB
testcase_18 AC 561 ms
59,460 KB
testcase_19 AC 500 ms
61,144 KB
testcase_20 AC 509 ms
62,708 KB
testcase_21 AC 414 ms
59,856 KB
testcase_22 AC 390 ms
59,944 KB
testcase_23 AC 370 ms
60,048 KB
testcase_24 AC 219 ms
56,172 KB
testcase_25 AC 220 ms
56,184 KB
testcase_26 AC 45 ms
49,264 KB
testcase_27 AC 44 ms
49,440 KB
testcase_28 AC 45 ms
49,320 KB
testcase_29 AC 45 ms
49,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long k = sc.nextLong();
        int p = sc.nextInt();
        int[] aArr = new int[n];
        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt() % p;
        }
        Arrays.sort(aArr);
        int[] bArr = new int[n];
        for (int i = 0; i < n; i++) {
            bArr[i] = sc.nextInt() % p;
        }
        Arrays.sort(bArr);
        int left = 0;
        int right = p;
        while (right - left > 1) {
            int m = (left + right) / 2;
            int one = n - 1;
            int zero = n - 1;
            int two = n - 1;
            long count = 0;
            for (int i = 0; i < n; i++) {
                while (one >= 0 && aArr[i] + bArr[one] >= m) {
                    one--;
                }
                count += one + 1;
                while (zero >= 0 && aArr[i] + bArr[zero] >= p) {
                    zero--;
                }
                while (two >= 0 && aArr[i] + bArr[two] >= p + m) {
                    two--;
                }
                count += two - zero;
            }
            if (count >= k) {
                right = m;
            } else {
                left = m;
            }
        }
        System.out.println(left);
    }
    
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0