Want to solve this problem? Login now to get access to solve the problems

Problem

Submissions

Solution

Leaderboard

Coming soon

1

Difficulty: EASY

Avg. time to solve

20 min

Success Rate

75%

Problem Statement

Suggest Edit

```
1. Length of each word should be less than or equal to M.
2. You can’t break a word, i.e. the entire word should come in the same line and it must not be the case that a part of it comes in the first line and another part on the next line.
```

```
The first line of the input contains an integer T denoting the number of Test cases.
The first line of each Test case should contain two positive integers N and M, where N is the number of words and M is the number of characters we require in each line.
Following N lines, contains one word each.
```

```
The only line of output of each test case should contain an integer denoting the minimum cost required to form the arrangement.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 100
1 <= N <= 300
1 <= |words[i]| <= 100
1 <= M <= 100
Time Limit: 1sec
```

```
1
3 6
ab
a
b
```

```
0
```

```
All the 3 words can be inserted in a single line.
ab a b Total Characters = 6
Hence extra spaces used are (6-6)^3=0
```

```
1
4 5
a
bc
def
ghij
```

```
10
```

```
The optimal output will be:
a bc
def
ghij
Hence extra spaces will be -> (1)^3 + (2)^3 + (1)^3 = 10
```

Want to solve this problem? Login now to get access to solve the problems