Problem:
Score : 1500 points

Problem Statement

Iroha has a sequence of N strings s_1, s_2, ..., s_N.

She will choose some (possibly all) strings from the sequence, then concatenate those strings retaining the relative order, to produce a long string.

Among all strings of length K that she can produce in this way, find the lexicographically smallest one.

Constraints

1 ≦ N ≦ 2000

1 ≦ K ≦ 10^4

For each i, 1 ≦ |s_i| ≦ K.

|s_1| + |s_2| + ... + |s_N| ≦ 10^6

For each i, s_i consists of lowercase letters.

There exists at least one string of length K that Iroha can produce.

Input

The input is given from Standard Input in the following format:

N K
s_1
s_2
:
s_N

Output

Print the lexicographically smallest string of length K that Iroha can produce.

Sample Input 1

3 7
at
coder
codar

Sample Output 1

atcodar

at and codar should be chosen.

Sample Input 2

3 7
coder
codar
at

Sample Output 2

codarat

codar and at should be chosen.

Sample Input 3

4 13
kyuri
namida
zzzzzzz
aaaaaa

Sample Output 3

namidazzzzzzz

namida and zzzzzzz should be chosen.

Solution in Rust (1.15.1) (judge verdict: Time Limit Exceeded)

use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let (n, k): (usize, usize) = stdin.lock().gets().split(' ').values();
    let strings = stdin.lock().lines().take(n)
        .map(|x| x.unwrap().into_bytes()).collect::<Vec<_>>();

    let mut best = vec![None; k + 1];
    best[0] = Some(Vec::new());
    for s in strings.iter().rev() {
        for len in (0..(k + 1 - s.len())).rev() {
            let newlen = s.len() + len;
            assert!(newlen <= k);
            let (best1, mut best2) = best.split_at_mut(newlen);
            if let Some(ref best1str) = best1[len] {
                if let Some(ref best2str) = best2[0] {
                    if !concat_lt(s, best1str, best2str) {
                        continue;
                    }
                }
                let mut newstr = s.clone();
                newstr.extend_from_slice(best1str);
                best2[0] = Some(newstr);
            }
        }
    }
    println!("{}", String::from_utf8_lossy(best[k].as_ref().unwrap()));
}

// Check if a1 + a2 is less than b.
// The lengths of a1 + a2 and b must be equal.
fn concat_lt(a1: &[u8], a2: &[u8], b: &[u8]) -> bool {
    use std::cmp::Ordering::*;
    match a1.cmp(&b[..a1.len()]) {
        Less => true,
        Equal => a2 < &b[a1.len()..],
        Greater => false,
    }
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}