結果

問題 No.871 かえるのうた
ユーザー akakimidori
提出日時 2019-09-04 15:15:52
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 918 bytes
コンパイル時間 13,265 ms
コンパイル使用メモリ 387,068 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-12-26 18:54:51
合計ジャッジ時間 15,778 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap() + 2;
    let k = it.next().unwrap().parse::<usize>().unwrap();
    let mut x = vec![-1_000_000_000_000_000_000i64; n];
    for i in 1..(n - 1) {
        x[i] = it.next().unwrap().parse().unwrap();
    }
    x[n - 1] = -x[n - 1];
    let mut a = vec![0i64; n];
    for i in 1..(n - 1) {
        a[i] = it.next().unwrap().parse().unwrap();
    }
    let mut i = k + 1;
    let mut r = x[k] + a[k];
    while x[i] <= r {
        r = std::cmp::max(r, x[i] + a[i]);
        i += 1;
    }
    let mut j = k - 1;
    let mut l = x[k]- a[k];
    while x[j] >= l {
        l = std::cmp::min(l, x[j] - a[j]);
        j -= 1;
    }
    let ans = i - j - 1;
    println!("{}", ans);
}

fn main() {
    run();
}
0