PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000258. Quảng cáo trên tạp chí (Magazine Ad)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Quảng cáo trên tạp chí (Magazine Ad)
Magazine Ad
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An advertisement string must fit in at most nonempty lines. Preserve every character in order. A line break is allowed only after a space or hyphen, which remains on the previous line and counts toward its length. Minimize the longest line length.
Input
The first line contains integer , the line limit. The second contains the complete string of uppercase/lowercase Latin letters, spaces and hyphens. Let .
Output
Print the minimum width.
Subtasks
- Subtask 1 (20 points): ; ; the string contains only uppercase/lowercase Latin letters, spaces and hyphens; every separator lies between two letters.
- Subtask 2 (30 points): ; ; the string contains only uppercase/lowercase Latin letters, spaces and hyphens; every separator lies between two letters. No hyphens; all words have equal length.
- Subtask 3 (50 points): ; ; the string contains only uppercase/lowercase Latin letters, spaces and hyphens; every separator lies between two letters.
Examples
Input
4
garage for sa-le
Output
7
Explanation
Use four lines garage , for , sa-, le, of lengths 7, 4, 3, 2. Trailing spaces count. The initial segment cannot be split before its space, so 7 is minimal.