結果

問題 No.2139 K Consecutive Sushi
ユーザー lddlinanlddlinan
提出日時 2023-03-22 20:27:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 91,540 KB
実行使用メモリ 10,896 KB
最終ジャッジ日時 2023-10-18 19:04:45
合計ジャッジ時間 2,631 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,240 KB
testcase_03 AC 38 ms
10,896 KB
testcase_04 AC 38 ms
10,896 KB
testcase_05 AC 39 ms
10,896 KB
testcase_06 AC 39 ms
10,896 KB
testcase_07 AC 39 ms
10,896 KB
testcase_08 AC 55 ms
7,216 KB
testcase_09 AC 56 ms
7,292 KB
testcase_10 AC 50 ms
8,588 KB
testcase_11 AC 56 ms
8,076 KB
testcase_12 AC 54 ms
7,216 KB
testcase_13 AC 2 ms
5,240 KB
testcase_14 AC 2 ms
5,240 KB
testcase_15 AC 3 ms
5,244 KB
testcase_16 AC 2 ms
5,240 KB
testcase_17 AC 2 ms
5,240 KB
testcase_18 AC 3 ms
5,308 KB
testcase_19 AC 2 ms
5,308 KB
testcase_20 AC 2 ms
5,304 KB
testcase_21 AC 2 ms
5,244 KB
testcase_22 AC 3 ms
5,320 KB
testcase_23 AC 5 ms
5,588 KB
testcase_24 AC 14 ms
6,608 KB
testcase_25 AC 27 ms
10,648 KB
testcase_26 AC 6 ms
5,604 KB
testcase_27 AC 12 ms
6,448 KB
testcase_28 AC 13 ms
6,580 KB
testcase_29 AC 7 ms
5,672 KB
testcase_30 AC 16 ms
7,692 KB
testcase_31 AC 34 ms
10,884 KB
testcase_32 AC 7 ms
5,828 KB
権限があれば一括ダウンロードができます

ソースコード

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];
    q.push({ss[n], n+1});
    for (i=n-1; i>=0; i--) {
        r = dp[i+1];
        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