結果

問題 No.1687 What the Heck?
ユーザー phsplsphspls
提出日時 2022-11-02 00:42:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 148,384 KB
実行使用メモリ 9,392 KB
最終ジャッジ日時 2023-09-23 12:24:55
合計ジャッジ時間 3,012 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 10 ms
4,672 KB
testcase_08 AC 14 ms
5,640 KB
testcase_09 AC 11 ms
4,556 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 28 ms
9,392 KB
testcase_13 AC 28 ms
9,196 KB
testcase_14 AC 29 ms
9,380 KB
testcase_15 AC 30 ms
9,096 KB
testcase_16 AC 29 ms
9,164 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 29 ms
9,388 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::Reverse;


fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut p = String::new();
    std::io::stdin().read_line(&mut p).ok();
    let p: Vec<usize> = p.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut result = 0usize;
    let mut exp = p.iter().sum::<usize>();
    let mut p = (0..n).map(|i| (i+1, p[i])).collect::<Vec<_>>();
    p.sort_by_key(|&(_, v)| Reverse(v));
    for &(i, _) in p.iter() {
        if exp > 2*i {
            result = result.max(exp - 2*i);
        }
        exp -= i;
    }
    println!("{}", result);
}
0