結果

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

ソースコード

diff #
raw source code

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

    let mut ans = -INF;
    let mut cur = 0;
    let mut hp = BinaryHeap::new();

    for (i, &aa) in a.iter().enumerate() {

        // 現在のスコアの合計
        hp.push(Reverse(aa));
        cur += aa;

        // Kを超えたら1個捨てる
        if hp.len() > k {
            cur -= hp.pop().unwrap().0;
        }

        let ret = cur - (i+1) as i64 * x;
        ans = max(ans, ret);
    }

    println!("{}", ans);
}
// const MOD93: usize = 998244353;
// const MOD17: usize = 1000000007;
// const INV2: usize = 499122177; // MOD93の剰余世界では、1/2の代わりにこれを掛ける
const INF: i64 = 1 << 60;
// const D: [(usize, usize); 4] = [(!0, 0), (0, !0), (1, 0), (0, 1)]; // 上左下右
// fn us(x: i32) -> usize { x as usize }

// 文字の定義
// const CHAR_SZ: usize = 26;
// const UPPER_A_ASCII : usize = 0x41;
// const UPPER_Z_ASCII : usize = UPPER_A_ASCII + SZ - 1;
// const LOWER_A_ASCII : usize = 0x61;
// const LOWER_Z_ASCII : usize = LOWER_A_ASCII + SZ - 1;
#[allow(unused)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
struct Pos {
    x: usize,
    y: usize,
}
#[allow(unused)]
enum Direction {
    UP = 0,
    LEFT = 1,
    DOWN = 2,
    RIGHT = 3,
}
#[allow(unused)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
struct LoopCount {
    ans: usize, // 答え
    step: usize, // 残りステップ
    pos: usize, // 現在位置
    cycle_len: usize, // サイクル数
    cycle_add: usize, // サイクルによる増加
}
#[allow(unused)]
use proconio::{input, marker::Chars, marker::Usize1};
// use proconio::{input, input_interactive, marker::Chars, marker::Usize1};

#[allow(unused)]
use std::{
    println, print,
    mem::swap,
    cmp::min, cmp::max,
    cmp::Reverse,
    collections::HashSet, collections::BTreeSet,
    collections::HashMap, collections::BTreeMap,
    collections::BinaryHeap,
    collections::VecDeque,
    iter::FromIterator,
};
#[allow(unused)]
use itertools::Itertools;
// #[allow(unused)]
// use num::{integer::gcd, Signed};
// #[allow(unused)]
// use num_integer::Roots;// 通常の平方根
// #[allow(unused)]
// use superslice::Ext;
// #[allow(unused)]
// use rand::Rng;
// let mut rng = rand::thread_rng();
// let n = rng.gen_range(1, 1000);

// 連想配列のデバッグ
#[allow(unused)]
fn dbg_print_mp(mp: &HashMap<usize, usize>) {
    for (&k, &v) in mp { println!("key:{} val:{}", k, v); }
}
// グリッドのデバッグ
#[allow(unused)]
fn dbg_print_grid(h: usize, w: usize, grid: &Vec<Vec<char>>) {
    for i in 0..h { for j in 0..w { print!("{}", grid[i][j]); } println!(); }
}
// 最短距離のデバッグ
#[allow(unused)]
fn dbg_print_dist(h: usize, w: usize, dist: &Vec<Vec<usize>>) {
    let limit = 255;
    for i in 0..h { for j in 0..w { print!("{:03} ", min(dist[i][j], limit)); } println!(); }
}
0