結果
| 問題 | 
                            No.2139 K Consecutive Sushi
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-03-22 20:24:10 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,128 bytes | 
| コンパイル時間 | 862 ms | 
| コンパイル使用メモリ | 91,424 KB | 
| 最終ジャッジ日時 | 2025-02-11 16:12:36 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 1 WA * 30 | 
コンパイルメッセージ
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];
    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;
}