結果
| 問題 | No.3656 Game Scores and Costs |
| コンテスト | |
| ユーザー |
aqua
|
| 提出日時 | 2026-08-30 13:46:25 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| + 695µs | |
| コード長 | 823 bytes |
| 記録 | |
| コンパイル時間 | 2,054 ms |
| コンパイル使用メモリ | 336,296 KB |
| 実行使用メモリ | 14,336 KB |
| 最終ジャッジ日時 | 2026-08-30 13:46:32 |
| 合計ジャッジ時間 | 4,863 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll N, K, X; cin >> N >> K >> X;
vector<ll> A(N);
for (auto &&a : A) cin >> a;
ll ans = -1LL << 60;
multiset<ll> high;
ll sum = 0;
for (int i = 0; i < K; ++i) {
high.insert(A[i]);
sum += A[i];
chmax(ans, sum - X * (i + 1));
}
for (int i = K; i < N; ++i) {
if (A[i] > *high.begin()) {
sum -= *high.begin();
high.erase(high.begin());
sum += A[i];
high.insert(A[i]);
}
chmax(ans, sum - X * (i + 1));
}
cout << ans << '\n';
}
aqua