結果

問題 No.258 回転寿司(2)
コンテスト
ユーザー srjywrdnprkt
提出日時 2022-12-31 06:36:32
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 864 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,228 ms
コンパイル使用メモリ 137,712 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-25 17:07:03
合計ジャッジ時間 13,241 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    int N, mx;
    cin >> N;
    vector<int> V(N+1), ans;
    for (int i=0; i<N; i++) cin >> V[i+1];
    vector<vector<int>> dp(N+1, vector<int>(2));

    for (int i=1; i<=N; i++){
        dp[i][0] = max({dp[i][0], dp[i-1][0], dp[i-1][1]});
        dp[i][1] = max(dp[i][1], dp[i-1][0] + V[i]);
    }

    mx = max(dp[N][0], dp[N][1]);
    cout << mx << endl;

    for (int i=N; i>=1; i--){
        if (mx == dp[i-1][0] + V[i]){
            ans.push_back(i);
            mx -= V[i];
        }
    }

    reverse(ans.begin(), ans.end());
    for (auto x : ans) cout << x << " ";
    cout << endl;

    return 0;
}
0