結果

問題 No.1093 区間の和 / Sum of Range
ユーザー phsplsphspls
提出日時 2020-06-29 23:08:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,204 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 145,256 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 11:25:51
合計ジャッジ時間 8,755 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 78 ms
4,376 KB
testcase_02 AC 38 ms
4,380 KB
testcase_03 AC 13 ms
4,376 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 119 ms
4,380 KB
testcase_06 AC 21 ms
4,380 KB
testcase_07 AC 63 ms
4,380 KB
testcase_08 AC 47 ms
4,380 KB
testcase_09 AC 104 ms
4,380 KB
testcase_10 AC 52 ms
4,376 KB
testcase_11 AC 107 ms
4,380 KB
testcase_12 AC 58 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 118 ms
4,376 KB
testcase_15 AC 24 ms
4,384 KB
testcase_16 AC 133 ms
4,376 KB
testcase_17 AC 114 ms
4,380 KB
testcase_18 AC 75 ms
4,376 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 60 ms
4,380 KB
testcase_21 AC 140 ms
4,380 KB
testcase_22 AC 129 ms
4,380 KB
testcase_23 AC 95 ms
4,380 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 116 ms
4,376 KB
testcase_26 AC 78 ms
4,376 KB
testcase_27 AC 125 ms
4,380 KB
testcase_28 AC 72 ms
4,380 KB
testcase_29 AC 145 ms
4,380 KB
testcase_30 AC 18 ms
4,384 KB
testcase_31 AC 23 ms
4,380 KB
testcase_32 AC 38 ms
4,376 KB
testcase_33 AC 125 ms
4,376 KB
testcase_34 AC 8 ms
4,376 KB
testcase_35 AC 138 ms
4,384 KB
testcase_36 AC 105 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut q = String::new();
    std::io::stdin().read_line(&mut q).ok();
    let q: usize = q.trim().parse().unwrap();
    let mut s: Vec<isize> = vec![];
    let first: isize = a.iter().take(k).sum();
    s.push(first);
    for i in 0..n-k {
        let prev = s[i];
        s.push(prev + a[k+i] - a[i]);
    }
    s.sort();
    for _ in 0..q {
        let mut x = String::new();
        std::io::stdin().read_line(&mut x).ok();
        let x: isize = x.trim().parse().unwrap();

        let mut lower: usize = 0;
        let mut upper: usize = s.len();
        while upper > lower {
            let middle = (upper + lower) / 2;
            if s[middle] > x {
                upper = middle;
            } else {
                lower = middle + 1;
            }
        }
        println!("{}", upper);
    }
}
0