結果
| 問題 | No.2139 K Consecutive Sushi |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-22 20:27:00 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,134 bytes |
| 記録 | |
| コンパイル時間 | 573 ms |
| コンパイル使用メモリ | 103,940 KB |
| 実行使用メモリ | 11,276 KB |
| 最終ジャッジ日時 | 2026-06-30 01:09:37 |
| 合計ジャッジ時間 | 2,122 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#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;
}