#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int n; int v[1000]; int dp[1001]; int before[1001]; signed main() { int i, j; cin >> n; for (i = 0; i < n; i++) { cin >> v[i]; before[i] = -1; } for (i = 0; i < n; i++) { //行きがけDP if (dp[min(i+2, n)] < dp[i] + v[i]) { before[min(i+2, n)] = i; dp[min(i+2, n)] = dp[i] + v[i]; } if (dp[i+1] < dp[i]) { dp[i+1] = dp[i]; before[i+1] = i; } } cout << dp[n] << endl; stack st; int cor = before[n]; do { st.push(cor); int inicor = cor; do { cor = before[cor]; } while (cor >= 0 && inicor - cor < 2); }while(cor >= 0); while(1) { cout << st.top() + 1<< " "; st.pop(); if (st.empty() ) { cout << endl; break; } } return 0; }