結果

問題 No.1248 Kth Sum
ユーザー momoyuumomoyuu
提出日時 2023-09-24 02:17:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,147 bytes
コンパイル時間 2,964 ms
コンパイル使用メモリ 249,100 KB
実行使用メモリ 7,284 KB
最終ジャッジ日時 2023-09-24 02:18:05
合計ジャッジ時間 6,463 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 28 ms
6,356 KB
testcase_15 WA -
testcase_16 AC 38 ms
6,476 KB
testcase_17 AC 35 ms
6,132 KB
testcase_18 AC 32 ms
6,140 KB
testcase_19 AC 35 ms
6,196 KB
testcase_20 AC 31 ms
6,428 KB
testcase_21 AC 29 ms
6,264 KB
testcase_22 AC 30 ms
6,140 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 43 ms
7,196 KB
testcase_25 AC 52 ms
7,204 KB
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 26 ms
6,256 KB
testcase_30 AC 40 ms
6,728 KB
testcase_31 AC 35 ms
6,132 KB
testcase_32 AC 32 ms
6,256 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    ll ans = 1e18;
    priority_queue<ll> que;
    priority_queue<ll> q1;
    vector<ll> use(n,1e18);
    ll sum = 0;
    if(k==1){
        cout<<a[0]<<endl;
        return 0;
    }
    ll last = -1;
    for(int i = n - 1;i>=0;i--){
        use[i] = a[i];
        if(i+1<n) use[i] = min(use[i],use[i+1]);
        if(i<k-1) break;
        ll need = (i+k-2)/(k-1);
        while(que.size()+1>need){
            sum -= que.top();
            que.pop();
        }
        if(que.size()+1==need){
            if(!que.empty()){
                ans = min(ans,sum+a[i]);
            }else{
                ll mx = need * k;
                mx--;
                if(que.top()<use[mx]){
                    ans = min(ans,sum+a[i]-que.top()+use[mx]);
                }else{
                    ans = min(ans,sum+a[i]);
                }
            }
        }
        sum += a[i];
        que.push(a[i]);
    }
    cout<<ans<<endl;
}

0