結果

問題 No.1248 Kth Sum
ユーザー momoyuumomoyuu
提出日時 2023-09-24 02:01:30
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 3,308 ms
コンパイル使用メモリ 248,960 KB
実行使用メモリ 5,688 KB
最終ジャッジ日時 2023-09-24 02:01:39
合計ジャッジ時間 6,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 29 ms
4,676 KB
testcase_15 WA -
testcase_16 AC 41 ms
5,032 KB
testcase_17 AC 34 ms
4,884 KB
testcase_18 AC 32 ms
4,676 KB
testcase_19 AC 32 ms
4,740 KB
testcase_20 AC 30 ms
4,668 KB
testcase_21 AC 30 ms
4,612 KB
testcase_22 AC 28 ms
4,616 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 43 ms
5,576 KB
testcase_25 AC 52 ms
5,688 KB
testcase_26 WA -
testcase_27 AC 24 ms
4,516 KB
testcase_28 AC 24 ms
4,564 KB
testcase_29 AC 23 ms
4,612 KB
testcase_30 AC 39 ms
5,176 KB
testcase_31 AC 34 ms
4,684 KB
testcase_32 AC 31 ms
4,516 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;
    ll res = 0;
    priority_queue<ll> que;
    ll sum = 0;
    if(k==1){
        cout<<a[0]<<endl;
        return 0;
    }
    ll last = -1;
    for(int i = n - 1;i>=0;i--){
        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){
            ans = min(ans,sum+a[i]);
        }
        if(need>=2){
            sum += a[i];
            que.push(a[i]);
        }else if(i==n-1){
            sum += a[i];
            que.push(a[i]);
        }
    }
    cout<<ans<<endl;

}

0