結果
| 問題 |
No.3050 Prefix Removal
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-07 22:00:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 255 ms / 2,000 ms |
| コード長 | 734 bytes |
| コンパイル時間 | 827 ms |
| コンパイル使用メモリ | 76,128 KB |
| 実行使用メモリ | 9,044 KB |
| 最終ジャッジ日時 | 2025-03-07 22:00:30 |
| 合計ジャッジ時間 | 12,161 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 55 |
ソースコード
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const ll INF = 8000000000000000000;
int main()
{
int n, k;
cin >> n >> k;
priority_queue<ll, vector<ll>, greater<ll>> que;
ll s;
cin >> s;
if (n == 1)
{
cout << s << endl;
return 0;
}
ll x = s;
ll ans = -INF;
for (int i = 1; i < n; i++)
{
ll a;
cin >> a;
que.push(-s);
s += a;
x += a * ((int)que.size() + 1);
if (i >= k)
{
ll t = que.top();
x -= s + t;
que.pop();
}
if ((int)que.size() == k - 1)
{
ans = max(ans, x);
}
}
cout << ans << endl;
}