結果

問題 No.1248 Kth Sum
ユーザー chocoruskchocorusk
提出日時 2020-12-28 10:58:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,412 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 131,732 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-10 10:02:39
合計ジャッジ時間 6,044 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,564 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 83 ms
6,944 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k; cin>>n>>k;
    ll a[200020];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    if(k==1){
        cout<<a[0]<<endl;
        return 0;
    }
    ll ans=1e18;
    for(int i=k-1; i<n; i++){
        int m=(i+k-2)/(k-1);
        if(m==1){
            ans=min(ans, a[i]);
            continue;
        }
        priority_queue<ll, vector<ll>, greater<ll>> que;
        for(int j=n-1; j>=k*m-1; j--){
            que.push(a[j]);
        }
        if(que.empty()) continue;
        ll ans1=a[i];
        ans1+=que.top(); que.pop();
        for(int j=m-1; j>=2; j--){
            for(int l=max(i+1, k*j-1); l<k*(j+1)-1; l++){
                que.push(a[l]);
            }
            if(que.empty()){
                ans1=1e18;
                break;
            }
            ans1+=que.top(); que.pop();
        }
        ans=min(ans, ans1);
    }
    cout<<ans<<endl;
    return 0;
}
0