結果

問題 No.1248 Kth Sum
ユーザー 👑 NachiaNachia
提出日時 2020-10-02 22:49:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 616 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 169,956 KB
実行使用メモリ 6,600 KB
最終ジャッジ日時 2023-09-24 22:19:26
合計ジャッジ時間 5,550 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 76 ms
4,896 KB
testcase_14 WA -
testcase_15 AC 76 ms
4,896 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 89 ms
5,680 KB
testcase_26 WA -
testcase_27 AC 76 ms
5,012 KB
testcase_28 AC 76 ms
4,924 KB
testcase_29 AC 83 ms
6,600 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
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;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N, K;
LL A[200000];

int main() {
    cin >> N >> K;
    rep(i, N) cin >> A[i];

    LL ans = A[K - 1];
    priority_queue<LL> Q;
    LL tmp = 0;
    for (int i = 2; i * K <= N; i++) {
        for (int j = (i - 1) * K - 1; j < i * K - 1; j++) {
            tmp += A[j];
            Q.push(A[j]);
        }
        rep(i, K - 1) {
            tmp -= Q.top(); Q.pop();
        }
        ans = min(ans, tmp + A[i * K - 1]);
    }

    cout << ans << endl;

    return 0;
}
0