結果
問題 |
No.3050 Prefix Removal
|
ユーザー |
|
提出日時 | 2025-03-08 00:40:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 1,127 bytes |
コンパイル時間 | 2,328 ms |
コンパイル使用メモリ | 198,808 KB |
実行使用メモリ | 12,592 KB |
最終ジャッジ日時 | 2025-03-08 00:40:49 |
合計ジャッジ時間 | 7,887 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 |
ソースコード
#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<<62; 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(); }