結果

問題 No.2028 Even Choice
ユーザー dyktr_06dyktr_06
提出日時 2022-08-05 23:10:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,831 bytes
コンパイル時間 3,609 ms
コンパイル使用メモリ 230,948 KB
実行使用メモリ 8,172 KB
最終ジャッジ日時 2023-10-14 00:57:04
合計ジャッジ時間 5,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
6,388 KB
testcase_01 AC 38 ms
7,900 KB
testcase_02 AC 40 ms
6,236 KB
testcase_03 AC 32 ms
8,172 KB
testcase_04 AC 32 ms
7,980 KB
testcase_05 AC 9 ms
4,348 KB
testcase_06 AC 38 ms
6,100 KB
testcase_07 AC 10 ms
4,368 KB
testcase_08 AC 26 ms
5,112 KB
testcase_09 AC 29 ms
5,872 KB
testcase_10 AC 10 ms
4,536 KB
testcase_11 AC 8 ms
4,352 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 27 ms
7,624 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 18 ms
5,132 KB
testcase_29 AC 12 ms
4,448 KB
testcase_30 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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();
}
0