結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー gyu-dongyu-don
提出日時 2017-08-11 17:12:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 20 ms / 3,000 ms
コード長 1,850 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 180,060 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 22:21:27
合計ジャッジ時間 1,825 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 19 ms
6,944 KB
testcase_08 AC 19 ms
6,940 KB
testcase_09 AC 11 ms
6,944 KB
testcase_10 AC 12 ms
6,944 KB
testcase_11 AC 12 ms
6,940 KB
testcase_12 AC 12 ms
6,944 KB
testcase_13 AC 20 ms
6,940 KB
testcase_14 AC 20 ms
6,944 KB
testcase_15 AC 19 ms
6,940 KB
testcase_16 AC 20 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused `Result` that must be used
 --> main.rs:6:9
  |
6 |         io::stdin().read_line(&mut s);
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this `Result` may be an `Err` variant, which should be handled
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
6 |         let _ = io::stdin().read_line(&mut s);
  |         +++++++

warning: unused `Result` that must be used
  --> main.rs:13:9
   |
13 |         io::stdin().read_line(&mut s);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
help: use `let _ = ...` to ignore the resulting value
   |
13 |         let _ = io::stdin().read_line(&mut s);
   |         +++++++

warning: unused `Result` that must be used
  --> main.rs:19:13
   |
19 |             io::stdin().read_line(&mut s);
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
help: use `let _ = ...` to ignore the resulting value
   |
19 |             let _ = io::stdin().read_line(&mut s);
   |             +++++++

warning: 3 warnings emitted

ソースコード

diff #

use std::io;

fn main() {
    let nm: Vec<u32> = {
        let mut s = String::new();
        io::stdin().read_line(&mut s);
        s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect()
    };
    let n = nm[0];
    let m = nm[1];
    let k: u32 = {
        let mut s = String::new();
        io::stdin().read_line(&mut s);
        s.trim().parse().unwrap()
    };
    let mut a: Vec<u32> = {
        (1..n).into_iter().map(|_| {
            let mut s = String::new();
            io::stdin().read_line(&mut s);
            s.trim().parse().unwrap()
        }).collect()
    };
    a.sort();

    let f = |i| {
        let us = k + a[i];
        let mut gt_us = 0;
        let mut tail = a.len() - 1;
        if tail == i {
            tail -= 1;
        }
        for head in 0..a.len() {
            if head == i {
                continue;
            }
            if head >= tail {
                break;
            }
            if a[head] + a[tail] > us {
                gt_us += 1;
                if gt_us >= m {
                    break;
                }
                tail -= 1;
                if tail == i {
                    tail -= 1;
                }
                continue;
            }
        }
        if gt_us < m {
            return a[i] as i32;
        }
        return -1;
    };
    if f(a.len() - 1) == -1 {
        println!("-1");
        return;
    }
    {
        let t = f(0);
        if t != -1 {
            println!("{}", a[0]);
            return;
        }
    }
    let mut head = 0;
    let mut tail = a.len() - 1;
    loop {
        let x = (head + tail) / 2;
        if tail - head < 2 {
            println!("{}", a[tail]);
            return;
        }
        let y = f(x);
        if y <= 0 {
            head = x;
        }
        else {
            tail = x;
        }
    }
}
0