結果

問題 No.3656 Game Scores and Costs
コンテスト
ユーザー urectanc
提出日時 2026-08-31 21:30:11
言語 Rust
(1.97.1 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 19 ms / 2,000 ms
+ 249µs
コード長 479 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,268 ms
コンパイル使用メモリ 182,712 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2026-08-31 21:30:18
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::{cmp::Reverse, collections::BinaryHeap};

use proconio::input;

fn main() {
    input! {
        n: usize, k: usize, x: i64,
        a: [i64; n],
    }

    let mut ans = i64::MIN;
    let mut sum = 0;
    let mut heap = BinaryHeap::new();
    for &a in &a {
        let b = a - x;
        sum += b;
        heap.push(Reverse(a));
        if heap.len() > k {
            sum -= heap.pop().unwrap().0;
        }
        ans = ans.max(sum);
    }
    println!("{ans}");
}
0