#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; // constexpr int mod = 1000000007; constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector V(N); for(int i = 0; i < N; ++i) cin >> V[i]; vector> dp(N + 1, vector(2, -1)); using P = pair; vector> restore(N + 1, vector

(2)); dp[0][0] = 0; for(int i = 0; i < N; ++i){ for(int j = 0; j < 2; ++j){ if(dp[i][j] == -1) continue; if(chmax(dp[i + 1][0], dp[i][j])){ restore[i + 1][0] = P(i, j); } if(j == 0 && chmax(dp[i + 1][1], dp[i][0] + V[i])){ restore[i + 1][1] = P(i, 0); } } } int i = N, j = -1, ans = -1; if(chmax(ans, dp[N][0])) j = 0; if(chmax(ans, dp[N][1])) j = 1; cout << ans << '\n'; vector idx; while(i > 0){ auto [ni, nj] = restore[i][j]; if(j == 1 && nj == 0) idx.emplace_back(i); i = ni, j = nj; } reverse(begin(idx), end(idx)); int n = idx.size(); for(i = 0; i < n; ++i){ cout << idx[i] << (i == n - 1 ? '\n' : ' '); } return 0; }