結果
| 問題 |
No.3050 Prefix Removal
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-03-09 03:21:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 2,000 ms |
| コード長 | 624 bytes |
| コンパイル時間 | 4,003 ms |
| コンパイル使用メモリ | 196,292 KB |
| 実行使用メモリ | 13,624 KB |
| 最終ジャッジ日時 | 2025-03-09 03:21:31 |
| 合計ジャッジ時間 | 9,470 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 55 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:15:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(i=1;i<=n;i++) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=5e5+10;
const int mod=998244353;
int a[MAX];
ll sum[MAX],res[MAX];
int main()
{
int n,k,i;
ll ans,now;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
sum[n+1]=0;
for(i=n;i;i--) sum[i]=sum[i+1]+a[i];
ans=-4e18;
now=0;
priority_queue<ll> q;
for(i=2;i<=n;i++)
{
now+=sum[i];
q.push(-sum[i]);
if(q.size()>k-1)
{
now-=(-q.top());
q.pop();
}
if(q.size()==k-1)
{
ans=max(ans,sum[1]+now-k*sum[i+1]);
}
}
printf("%lld\n",ans);
return 0;
}
vjudge1