PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000343. Tăng dãy theo phép chia dư (Increasing by Modulo)
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ăng dãy theo phép chia dư (Increasing by Modulo)
Increasing by Modulo
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers in , an operation selects any set of distinct indices and increments their values modulo m simultaneously. Find the minimum number of operations needed to make the array nondecreasing.
Input
First line: . Second line: integers .
Output
Print the minimum number of operations.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Examples
Input 1
5 7
0 6 1 3 2
Output 1
1
Explanation
Increment positions 2 and 5 to obtain [0,0,1,3,3]. The initial array is not nondecreasing.
Input 2
4 3
0 0 1 2
Output 2
0
Explanation
The array is already nondecreasing.