Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <queue>
- #include <algorithm>
- #define task ""
- #define pb push_back
- #define ld long double
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- const int sizearr = 100003;
- inline void fastIOfileinput(){
- ios_base:: sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if(fopen(task".inp", "r")){
- freopen(task".inp", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- if(fopen(task".in", "r")){
- freopen(task".in", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- }
- ll n, a[100009], sum;
- int m;
- ll f[100009];
- bool ck[4][100009];
- inline void Enter(){
- cin >> n;
- for(int i = 1; i <= n; ++i) cin >> a[i];
- }
- void trace(int i){
- if(i == 1){
- cout << 1 << " ";
- return;
- }
- if(i == 2){
- cout << "1 2 ";
- return;
- }
- if(ck[2][i]){
- trace(i - 2);
- cout << i << " ";
- }
- if(ck[3][i]){
- trace(i - 3);
- cout << i - 1 << " " << i << " ";
- }
- if(ck[1][i]) trace(i - 1);
- }
- inline void solve(){
- f[1] = 1;
- f[2] = f[1] + a[2];
- for(int i = 3; i <= n; ++i){
- ck[1][i] = ck[2][i] = ck[3][i] = 0;
- f[i] = max(f[i - 1], max(f[i - 2] + a[i], f[i - 3] + a[i] + a[i - 1]));
- if(f[i] == f[i - 1]) ck[1][i] = 1;
- else if(f[i] == f[i - 2] + a[i]) ck[2][i] = 1;
- else ck[3][i] = 1;
- }
- cout << f[n] << "\n";
- trace(n);
- }
- int main(){
- fastIOfileinput();
- int t;
- Enter();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement