結果
問題 | No.2139 K Consecutive Sushi |
ユーザー |
|
提出日時 | 2023-03-22 20:27:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 1,134 bytes |
コンパイル時間 | 956 ms |
コンパイル使用メモリ | 91,648 KB |
最終ジャッジ日時 | 2025-02-11 16:12:41 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d %d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:36:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | for (i=0; i<n; i++) scanf("%d", &as[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#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; }