Submission #46665577


Source Code Expand

use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [i64; n],
    }

    let mut s = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, &i| {
            *acc += i;
            Some(*acc)
        }))
        .collect::<Vec<i64>>();

    s.sort();

    let mut ok = 1_i64 << 60;
    let mut ng = -1_i64;
    while ok - ng > 1 {
        let x = (ok + ng) / 2;

        let mut count = 0_usize;
        let mut l = 0_usize;
        let mut r = 0_usize;
        for i in 0..=n {
            while s[l] < s[i] - x {
                l += 1;
            }
            while r < n && s[r + 1] <= s[i] + x {
                r += 1;
            }

            count += r - l;
        }

        if count >= 2 * k {
            ok = x;
        } else {
            ng = x;
        }
    }

    println!("{}", ok);
}

Submission Info

Submission Time
Task L - K-th Abs
User bouzuya
Language Rust (rustc 1.70.0)
Score 6
Code Size 853 Byte
Status AC
Exec Time 191 ms
Memory 10840 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 03_k_max_00.txt, 03_k_max_01.txt, 04_k_max_a_max_00.txt, 04_k_max_a_max_01.txt, 05_k_min_00.txt, 05_k_min_01.txt, 06_bound_00.txt, 06_bound_01.txt, 06_bound_02.txt, 06_bound_03.txt, 06_bound_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 1936 KiB
00_sample_01.txt AC 1 ms 1888 KiB
00_sample_02.txt AC 1 ms 2044 KiB
01_small_00.txt AC 1 ms 2028 KiB
01_small_01.txt AC 1 ms 1936 KiB
01_small_02.txt AC 1 ms 1992 KiB
01_small_03.txt AC 1 ms 1828 KiB
01_small_04.txt AC 1 ms 1888 KiB
01_small_05.txt AC 1 ms 1824 KiB
01_small_06.txt AC 1 ms 1824 KiB
01_small_07.txt AC 1 ms 1824 KiB
01_small_08.txt AC 1 ms 2116 KiB
01_small_09.txt AC 1 ms 2084 KiB
02_random_00.txt AC 156 ms 10728 KiB
02_random_01.txt AC 136 ms 10488 KiB
02_random_02.txt AC 187 ms 10504 KiB
02_random_03.txt AC 191 ms 10720 KiB
02_random_04.txt AC 119 ms 10512 KiB
03_k_max_00.txt AC 74 ms 10568 KiB
03_k_max_01.txt AC 75 ms 10828 KiB
04_k_max_a_max_00.txt AC 61 ms 10284 KiB
04_k_max_a_max_01.txt AC 60 ms 9920 KiB
05_k_min_00.txt AC 149 ms 10736 KiB
05_k_min_01.txt AC 148 ms 10840 KiB
06_bound_00.txt AC 66 ms 8212 KiB
06_bound_01.txt AC 65 ms 8068 KiB
06_bound_02.txt AC 66 ms 8152 KiB
06_bound_03.txt AC 67 ms 8112 KiB
06_bound_04.txt AC 66 ms 8092 KiB