結果

問題 No.258 回転寿司(2)
ユーザー kurenai3110
提出日時 2016-10-18 17:35:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 66,756 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 19:08:02
合計ジャッジ時間 3,944 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int DP[1001][2];

int main()
{
	int n; cin >> n;
	vector<int>V;
	for (int i = 0; i < n; i++) {
		int v; cin >> v;
		V.push_back(v);
		for (int k = 0; k < 2; k++) {
			if (k == 0) {
				DP[i + 1][1] = DP[i][k] + v;
				DP[i + 1][0] = DP[i][k];
			}
			else {
				DP[i + 1][0] = max(DP[i+1][0], DP[i][k]);
			}
		}
	}

	int max_number = max(DP[n][1], DP[n][0]);
	cout << max_number << endl;
	vector<int>num;
	for (int i = 0; i < n; i++) {
		bool which = max_number == DP[n-i][1];
		if (which) {
			num.push_back(n - i);
			max_number -= V[n - i - 1];
		}
	}

	sort(num.begin(), num.end());
	for (int i = 0; i < num.size(); i++) {
		if (i)cout << " ";
		cout << num[i];
	}
	cout << endl;

    return 0;
}

0