結果

問題 No.1248 Kth Sum
ユーザー chocoruskchocorusk
提出日時 2020-12-28 13:12:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,511 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 136,472 KB
実行使用メモリ 16,036 KB
最終ジャッジ日時 2024-04-14 06:17:44
合計ジャッジ時間 8,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 84 ms
6,940 KB
testcase_14 AC 182 ms
13,220 KB
testcase_15 AC 85 ms
6,940 KB
testcase_16 AC 200 ms
14,548 KB
testcase_17 AC 220 ms
15,700 KB
testcase_18 AC 219 ms
15,772 KB
testcase_19 AC 214 ms
15,784 KB
testcase_20 AC 223 ms
15,912 KB
testcase_21 AC 208 ms
15,652 KB
testcase_22 AC 182 ms
13,352 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 150 ms
11,248 KB
testcase_25 AC 155 ms
8,880 KB
testcase_26 AC 171 ms
12,964 KB
testcase_27 AC 84 ms
6,944 KB
testcase_28 AC 84 ms
6,940 KB
testcase_29 AC 83 ms
6,944 KB
testcase_30 AC 151 ms
14,116 KB
testcase_31 AC 162 ms
15,780 KB
testcase_32 AC 161 ms
15,780 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 232 ms
16,036 KB
testcase_37 AC 218 ms
15,272 KB
権限があれば一括ダウンロードができます

ソースコード

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=a[k-1];
    priority_queue<P, vector<P>, greater<P>> que;
    priority_queue<P> que1;
    ll s=0;
    bool dame[200020]={};
    for(int j=n/k; j>=2; j--){
        for(int i=k*j-1; i<min(n, k*(j+1)-1); i++){
            que.push({a[i], i});
        }
        que1.push(que.top());
        s+=que.top().first;
        dame[que.top().second]=1;
        que.pop();
    }
    multiset<ll> st;
    for(int i=k-1; i<=(k-1)*(n/k); i++) if(!dame[i]) st.insert(a[i]);
    for(int i=n/k; i>=2; i--){
        ans=min(ans, *st.begin()+s);
        s-=que1.top().first;
        int t=que1.top().second;
        dame[t]=0;
        if(t<=(k-1)*i) st.insert(a[t]);
        que1.pop();
        for(int j=(k-1)*i; j>(k-1)*(i-1); j--){
            if(!dame[j]) st.erase(st.lower_bound(a[j]));
        }
    }
    cout<<ans<<endl;
    return 0;
}
0