PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000107. Đồng nghiệp khó chịu (Annoyed Coworkers)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đồng nghiệp khó chịu (Annoyed Coworkers)
Annoyed Coworkers
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
You need help requests assigned among coworkers. Coworker initially has annoyance , which increases by for each request assigned to that coworker. Requests may be assigned repeatedly to anyone. Minimize the maximum final annoyance over all coworkers.
Input
Line 1 contains . The following lines contain .
Output
Print the minimum possible maximum final annoyance.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
4 4
1 2
2 3
3 4
4 5
Output
7
Explanation
Assign three requests to coworker , raising annoyance to , and one request to coworker , raising annoyance to . Others remain at . The maximum is , which is optimal.