use proconio::input; fn main() { input! { n: usize, tot: usize, a: [usize; n] } let mut dp = vec![vec![false; tot + 1]; n + 1]; dp[n][tot] = true; for i in (0..n).rev() { for j in 0..=tot { if j + a[i] <= tot && dp[i + 1][j + a[i]] { dp[i][j] = true; } if j * a[i] <= tot && dp[i + 1][j * a[i]] { dp[i][j] = true; } } } let mut cur = a[0]; let mut ans: String = String::new(); for i in 1..n { if cur + a[i] <= tot && dp[i + 1][cur + a[i]] { cur += a[i]; ans.push('+'); }else { cur *= a[i]; ans.push('*'); } } println!("{}", ans); }