結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-10-13 23:12:57 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 3,000 ms | 
| コード長 | 3,449 bytes | 
| コンパイル時間 | 18,748 ms | 
| コンパイル使用メモリ | 390,000 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-17 11:45:57 | 
| 合計ジャッジ時間 | 20,820 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 | 
ソースコード
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BTreeSet};
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}
#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}
fn rank(k: usize, buddy: usize, a: &[usize]) -> usize {
    let t = k + buddy;
    let mut l = 0;
    let mut r = a.len() - 1;
    let mut cnt = 0;
    let mut skipped = false;
    while r > l {
        if !skipped && a[l] == buddy {
            l += 1;
            skipped = true;
            continue;
        }
        if !skipped && a[r] == buddy {
            r -= 1;
            skipped = true;
            continue;
        }
        if a[l] + a[r] > t {
            r -= 1;
            l += 1;
            cnt += 1;
        } else {
            l += 1;
        }
    }
    cnt
}
fn bin_search(low: usize, high: usize, a: &[usize], scores: &[usize], k: usize, m: usize) -> i64 {
    let mid = (low + high) / 2;
    if low == high {
        return scores.get(low).cloned().map(|i| i as i64).unwrap_or(-1);
    }
    match rank(k, scores[mid], a).cmp(&m) {
        Ordering::Less => bin_search(low, mid, a, scores, k, m),
        Ordering::Equal => bin_search(low, mid, a, scores, k, m),
        Ordering::Greater => bin_search(mid + 1, high, a, scores, k, m),
    }
}
fn main() {
    let (n, m): (usize, usize) = util::get2();
    let k: usize = util::get();
    let mut a: Vec<usize> = (1..n).map(|_| util::get()).collect();
    a.sort();
    let mut scores = a.clone();
    scores.dedup();
    println!("{}", bin_search(0, scores.len(), &a, &scores, k, m - 1));
}
            
            
            
        