結果
問題 |
No.258 回転寿司(2)
|
ユーザー |
![]() |
提出日時 | 2022-12-31 06:36:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 864 bytes |
コンパイル時間 | 822 ms |
コンパイル使用メモリ | 111,804 KB |
最終ジャッジ日時 | 2025-02-09 22:22:50 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#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; }