結果

問題 No.258 回転寿司(2)
ユーザー latte0119
提出日時 2015-08-06 13:44:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 160,508 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-06 18:51:55
合計ジャッジ時間 4,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int dp[10000];
int N;
int V[10000];


int main(){
    cin>>N;
    for(int i=0;i<N;i++)cin>>V[i];

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

    vector<int>ans;
    int cur=N+1;

    while(cur>1){
        if(dp[cur]==dp[cur-1]){
            cur--;
            continue;
        }
        cur-=2;
        ans.push_back(cur+1);
    }

    reverse(ans.begin(),ans.end());

    cout<<dp[N+1]<<endl;

    for(int i=0;i<ans.size();i++){
        if(i)cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;

    return 0;

}
0