結果

問題 No.258 回転寿司(2)
ユーザー h_noson
提出日時 2016-05-07 19:36:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 62,868 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-06 19:01:57
合計ジャッジ時間 3,889 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

int main() {
    int i, n;
    int dp[2][1000], v[1000];
    vector<int> ans;
    cin >> n;
    rep (i,n) cin >> v[i];
    dp[0][0] = 0;
    dp[1][0] = v[0];
    REP (i,1,n-1) {
        dp[0][i] = max(dp[0][i-1],dp[1][i-1]);
        dp[1][i] = dp[0][i-1] + v[i];
    }
    int taste = max(dp[0][n-1],dp[1][n-1]);
    cout << taste << endl;
    rrep (i,n) {
        if (dp[1][i] == taste) {
            ans.push_back(i+1);
            taste -= v[i];
        }
    }
    rrep (i,ans.size())
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}
0