#BS0000315. Lễ hội đồ chơi gỗ (Wooden Toy Festival)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lễ hội đồ chơi gỗ (Wooden Toy Festival)
Wooden Toy Festival
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A town is preparing for a wooden toy festival. Its workshop has three carvers and expects customers. Customer requests a toy with integer pattern .
Before the festival, each carver selects an integer pattern in to practise. Producing pattern then takes units of time. A carver can handle several orders simultaneously, so a customer's waiting time depends only on the requested and practised patterns.
Choose the three practised patterns and assign each customer to one carver to minimize the maximum waiting time among all customers.
Input
- The first line contains the integer , the number of customers.
- The second line contains integers , the requested patterns.
Output
Print one integer: the minimum possible maximum waiting time.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Examples
Input 1
6
5 4 2 1 30 60
Output 1
2
Explanation
Select patterns 3, 30 and 60. Requests 5, 4, 2 and 1 wait 2, 1, 1 and 2 units respectively; the other two wait zero. A limit of 1 requires separate carvers for 1, 5, 30 and 60. Three carvers cannot achieve it, so the answer is 2.
Input 2
6
1 7 7 9 9 9
Output 2
0
Explanation
Choose patterns 1, 7 and 9. Every customer is assigned to a carver who has practised the requested pattern, so all waiting times are zero, which is the lower bound.
Input 3
9
14 19 37 59 1 4 4 98 73
Output 3
13
Explanation
Choose patterns 14, 50 and 85 for groups (1,4,4,14,19), (37,59) and (73,98); each group's maximum wait is 13. With a limit of 12, requests 1, 37, 73 and 98 have pairwise distances of at least 25, so they need four different carvers.
Input 4
1
2
Output 4
0
Explanation
The only customer requests pattern 2. One carver practises pattern 2, so the customer waits zero time.
Input 5
6
3 10 1 17 15 11
Output 5
1
Explanation
Choose patterns 2, 10 and 16 for groups (1,3), (10,11) and (15,17). Each group has maximum wait 1. Zero waiting would require six carvers for six distinct patterns.