結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2024-03-30 01:59:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 519 bytes |
コンパイル時間 | 2,001 ms |
コンパイル使用メモリ | 198,404 KB |
最終ジャッジ日時 | 2025-02-20 15:49:25 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin>>N>>K; vector<ll>A(N); for(int i=0;i<N;i++)cin>>A[i]; priority_queue<ll,vector<ll>,greater<ll>>pq; ll sum=0,ans=0; for(int i=N-1;i>=0;i--){ if(pq.size()<K-1){ pq.push(A[i]); sum+=A[i]; } else{ if(i%2==1)ans=max(ans,A[i]+sum); if(pq.size()&&pq.top()<A[i]){ sum-=pq.top(); pq.pop(); sum+=A[i]; pq.push(A[i]); } } } cout<<ans<<"\n"; }