using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int itemCount = int.Parse(Reader.ReadLine()); this.sushi = Reader.GetInt(); List ans = this.GetAns(0); ans.Sort(); Console.WriteLine(ans.Sum(a=>this.sushi[a])); ans = new List(ans.Select(a=>a+1)); Console.WriteLine(string.Join(" ", ans)); } private int[] sushi ; Dictionary> dic = new Dictionary>(); public List GetAns(int idx) { if(dic.ContainsKey(idx)) { return dic[idx]; } List ans = new List(); int max = 0; if(idx >= this.sushi.Length) { } else if(idx == this.sushi.Length - 1) { ans.Add(idx); } else { List tmp = new List(this.GetAns(idx + 2)); tmp.Add(idx); int total = tmp.Sum(a=>this.sushi[a]); if(total > max) { max = total; ans = tmp; } tmp = new List(this.GetAns(idx + 1)); total = tmp.Sum(a=>this.sushi[a]); if(total > max) { max = total; ans = tmp; } } this.dic.Add(idx, ans); return ans; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 7 1 2 9 10 1 1 4 ı "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }