結果

問題 No.3050 Prefix Removal
ユーザー GOTKAKO
提出日時 2025-03-07 22:40:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 704 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 197,784 KB
実行使用メモリ 13,072 KB
最終ジャッジ日時 2025-03-07 22:41:01
合計ジャッジ時間 7,951 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,K; cin >> N >> K;
    priority_queue<long long> Q;
    long long answer= -3e18,now = 0;
    vector<long long> A(K);
    for(auto &a : A) cin >> a;
    
    for(int i=K-1; i>=0; i--){
        now += A.at(i)*(i+1);
        if(i < K-1) A.at(i) += A.at(i+1);
        if(i) Q.push(A.at(i));
    }

    answer = now;
    long long zero = 0;
    for(int i=K; i<N; i++){
        long long a; cin >> a;
        Q.push(zero); zero -= a;
        long long add = Q.top(); Q.pop();
        add -= zero; now += add;
        answer = max(answer,now);
    }
    cout << answer << endl;
}  
0