結果

問題 No.3656 Game Scores and Costs
コンテスト
ユーザー こっとん
提出日時 2026-08-30 14:45:25
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 21 ms / 2,000 ms
+ 637µs
コード長 1,533 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,346 ms
コンパイル使用メモリ 356,428 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2026-08-30 14:45:38
合計ジャッジ時間 4,669 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
// #include <atcoder/dsu>
// #include<atcoder/modint>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<< "Yes"<< endl
#define NO cout<< "No"<< endl
#define Rep(i,s,n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
template<class T, class U> bool chmax(T& x, const U& y){
    if (x < y) { x = y; return true; }
    return false;
}
template<class T, class U> bool chmin(T& x, const U& y){
    if (y < x) { x = y; return true; }
    return false;
}
#define UNIQUE(a) a.erase(unique(a.begin(),a.end()),a.end())
using namespace std;
// using mint = atcoder::modint998244353;
// using mint2 = atcoder::modint1000000007;
// using namespace atcoder;
using ll = long long;
using V = vector<ll>;
using P = pair<ll,ll>;
using i128 = __int128;

void solve(){
    ll n,k,x; cin >> n >> k >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    priority_queue<ll,vector<ll>,greater<ll>> q;
    vector<ll> c(n);
    ll now = 0;
    rep(i,n){
        if(i+1 > k){
            if(q.top() < a[i]){
                now += a[i]-q.top();
                q.pop();
                q.push(a[i]);
            }
        }
        else {
            q.push(a[i]);
            now+= a[i];
        }
        c[i] = now -(i+1)*x;
    }
    ll ans = -12345678901234;
    rep(i,n) chmax(ans,c[i]);
    cout << ans << endl;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t; 
    t = 1;
    //cin >> t;
    rep(i,t) solve();
}
0