結果

問題 No.1248 Kth Sum
ユーザー chocorusk
提出日時 2020-10-07 21:51:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 127,380 KB
最終ジャッジ日時 2025-01-15 03:18:21
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 25
権限があれば一括ダウンロードができます

ソースコード

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 <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
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];
    }
    priority_queue<ll> que;
    ll ans=a[k-1];
    ll s=0;
    for(int i=1; (i+1)*k-1<n; i++){
        int jmn=i*k-1;
        for(int j=i*k-1; j<(i+1)*k-1; j++){
            if(a[jmn]>a[j]){
                jmn=j;
            }
        }
        for(int j=i*k-1; j<(i+1)*k-1; j++){
            if(j==jmn) continue;
            que.push(a[j]);
            s+=a[j];
            while(que.size()>i-1){
                ll x=que.top();
                que.pop();
                s-=x;
            }
        }
        que.push(a[jmn]);
        s+=a[jmn];
        ans=min(ans, s+a[(i+1)*k-1]);
    }
    cout<<ans<<endl;
    return 0;
}
0