結果

問題 No.258 回転寿司(2)
ユーザー h_noson
提出日時 2016-05-07 19:34:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 915 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 63,120 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 11:46:25
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
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];
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    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