PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000303. Tối đa khoảng cách giữa các số được chọn (Maximize Score of Numbers in Ranges)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tối đa khoảng cách giữa các số được chọn (Maximize Score of Numbers in Ranges)
Maximize Score of Numbers in Ranges
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given integer intervals , choose one integer from each. The score is . Maximize this score. Chosen values may coincide.
Input
First line: . Second line: integers .
Output
Print the maximum score.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Examples
Input 1
3 2
6 0 3
Output 1
4
Explanation
Choose 8,0,4 in the original interval order. A gap of 5 would require a third sorted value at least 10, beyond 8.