PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000216. Người lính và phù hiệu (Soldier and Badges)
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ười lính và phù hiệu (Soldier and Badges)
Soldier and Badges
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are soldiers, each with a badge whose initial coolness factor is . Spending one coin increases the factor of any badge by exactly . All final coolness factors must be pairwise distinct. You cannot decrease a factor or exchange badges between soldiers. Calculate the minimum total number of coins required.
Input
- Line 1 contains , the number of soldiers.
- Line 2 contains exactly integers , the initial coolness factors of their badges.
Output
Print one integer: the minimum number of coins that must be spent.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
5
1 2 3 2 5
Output
2
Explanation
Initial values are , so two badges have factor . Keep one at and increase the other to , at a cost of two coins, giving distinct factors . Spending only one coin would turn the duplicate into another duplicate at . Thus the answer is .