結果

問題 No.2139 K Consecutive Sushi
ユーザー lddlinanlddlinan
提出日時 2023-03-22 20:24:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,128 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 91,312 KB
実行使用メモリ 10,896 KB
最終ジャッジ日時 2023-10-18 19:04:42
合計ジャッジ時間 5,177 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};


int as[200004];
LL ss[200004];
LL dp[200004];
int main() {
    int n, i, k;
    LL r;
    scanf("%d %d", &n, &k);
    dp[n]=dp[n+1]=0;
    priority_queue<pair<LL, int>> q;
    for (i=0; i<n; i++) scanf("%d", &as[i]);
    ss[0]=0; for (i=0; i<n; i++) ss[i+1]=ss[i]+as[i];
    for (i=n-1; i>=0; i--) {
        r = max(dp[i+1], as[i]+dp[i+2]);
        while(!q.empty()) {
            auto x = q.top();
            if (x.second-i<=k) break;
            q.pop();
        }
        if (!q.empty()) {
            auto x = q.top();
            r = max(r, x.first-ss[i]);
        }
        dp[i]=r;
        q.push({dp[i+1]+ss[i], i+1});
    }
    printf("%lld\n", dp[0]);
    return 0;
}
0