結果
問題 | No.3050 Prefix Removal |
ユーザー |
|
提出日時 | 2025-03-08 00:39:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,127 bytes |
コンパイル時間 | 2,168 ms |
コンパイル使用メモリ | 197,496 KB |
実行使用メモリ | 13,108 KB |
最終ジャッジ日時 | 2025-03-08 00:39:49 |
合計ジャッジ時間 | 8,151 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 54 WA * 1 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll=long long;#define all(v) v.begin(),v.end()#define rall(v) v.rbegin(),v.rend()template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}const ll INF=1LL<<60;void Solve(){int N,K;cin>>N>>K;vector<ll>A(N);for(int i=0;i<N;i++)cin>>A[i];if(K==1){ll sum=0,ans=-INF;for(int i=0;i<N;i++){sum+=A[i];chmax(ans,sum);}cout<<ans<<"\n";return;}ll pf=0,sum=0;priority_queue<ll>pq;ll ans=-INF;for(int i=0;i<N;i++){if(pq.size()<K-1){pf+=A[i];sum+=pf;pq.push(pf);continue;}chmax(ans,K*(pf+A[i])-sum);pf+=A[i];if(pf<pq.top()){sum-=pq.top();pq.pop();pq.push(pf);sum+=pf;}}cout<<ans<<"\n";}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);Solve();}