using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int itemCount = int.Parse(Reader.ReadLine()); this.Total = long.Parse(Reader.ReadLine()); this.Items = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); List ans = GetAns(0, Items[0]); Console.WriteLine(string.Join(string.Empty, ans)); } private long[] Items; private long Total; private List GetAns(int idx, long subTotal) { if(subTotal>Total) { return null; } if(idx == Items.Length - 1) { if(subTotal == Total) { return new List(); } else { return null; } } List ans = new List(); List ret = GetAns(idx + 1, subTotal + Items[idx + 1]); if(ret != null) { ans.Add('+'); ans.AddRange(ret); return ans; } ret = GetAns(idx + 1, subTotal * Items[idx + 1]); if (ret != null) { ans.Add('*'); ans.AddRange(ret); return ans; } return null; } public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 4 31 1 2 10 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }