結果

問題 No.1046 Fruits Rush
ユーザー seinyan
提出日時 2021-11-05 11:15:49
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 27,076 ms
コンパイル使用メモリ 387,028 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-15 19:59:25
合計ジャッジ時間 15,387 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let v1 = input_line_vc::<usize>();
    let mut a = input_line_vc::<i32>();

    a.sort();
    a.reverse();

    let mut result = 0;
    if a[0] < 0 {
        println!("{}", a[0]);
        return;
    }
    for i in 0..v1[1] {
        if a[i] >= 0 {
            result += a[i];
        }
    }
    println!("{}", result);
}

fn input_line_vc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0