问题 A: Magazine Ad

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:24 通过:6

题目描述

https://codeforces.com/problemset/problem/803/D


D. Magazine Ad
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more than one hyphen.
It is guaranteed that there are no adjacent spaces and no adjacent hyphens. No hyphen is adjacent to space. There are no spaces and no hyphens before the first word and after the last word.
When the word is wrapped, the part of the word before hyphen and the hyphen itself stay on current line and the next part of the word is put on the next line. You can also put line break between two words, in that case the space stays on current line. Check notes for better understanding.
The ad can occupy no more that k lines and should have minimal width. The width of the ad is the maximal length of string (letters, spaces and hyphens are counted) in it.
You should write a program that will find minimal width of the ad.
Input
The first line contains number k (1≤k≤105).
The second line contains the text of the ad − non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters.
Output
Output minimal width of the ad.
Examples
Input
4
garage for sa-le
Output
7
Input
4
Edu-ca-tion-al Ro-unds are so fun
Output
10
Note
Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
garage.
for.
sa-
le
The second example:
Edu-ca-
tion-al.
Ro-unds.
are.so.fun



《主要城市》杂志为读者提供了刊登广告的机会。广告的格式应该是这样的:

有小写和大写拉丁字母的空格分隔的非空单词。

有些单词中有连字符“-”,它们的位置设置单词换行点。单词可以包含多个连字符。

保证没有相邻的空格和连字符。空格旁边没有连字符。在第一个单词之前和最后一个单词之后没有空格和连字符。

当单词被换行时,连字符之前的单词部分和连字符本身保留在当前行上,单词的下一部分放在下一行上。您还可以在两个单词之间放置换行符,在这种情况下,空格将保留在当前行上。检查注释以更好地理解。

广告不能占用超过k行,并且应该具有最小的宽度。广告的宽度是其中字符串的最大长度(包括字母、空格和连字符)。

你应该编写一个程序,找出广告的最小宽度。


输入格式

第一行包含数字k(1≤k≤105)。

第二行包含广告的文本——非空格分隔的小写和大写拉丁字母和连字符的单词。广告的总长度不超过106个字符。

输出格式

输出广告的最小宽度。

输入样例 复制

4
garage for sa-le

输出样例 复制

7

数据范围与提示

这里所有的空格都用点代替。

在第一个示例中,所有单词换行后的一个可能结果如下:
garage.
for.
sa-
le
第二个例子:
Edu-ca-
tion-al.
Ro-unds.
are.so.fun