結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-05 23:10:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 1,831 bytes |
| コンパイル時間 | 3,794 ms |
| コンパイル使用メモリ | 232,308 KB |
| 実行使用メモリ | 8,312 KB |
| 最終ジャッジ日時 | 2024-09-15 20:43:18 |
| 合計ジャッジ時間 | 5,653 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define out(a) cout << a << "\n"
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef pair<long long, long long> P;
const long long INF = 0x1fffffffffffffff;
const long long MOD = 1000000007;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
ll n, k;
vll a;
void input(){
cin >> n >> k;
vin(a, n);
}
void solve(){
ll ans = 0, sum = 0;
priority_queue<ll, vll, greater<ll>> q;
for(int i = n - 1; i >= 1; i--){
if(i % 2 == 0){
q.push(a[i]);
sum += a[i];
if(q.size() > k - 1){
ll t = q.top(); q.pop();
sum -= t;
}
}else{
chmax(ans, a[i] + sum);
q.push(a[i]);
sum += a[i];
if(q.size() > k - 1){
ll t = q.top(); q.pop();
sum -= t;
}
}
}
out(ans);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
input();
solve();
}