PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000191. Gán bằng hoặc giảm đi (Set or Decrease)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Gán bằng hoặc giảm đi (Set or Decrease)
Set or Decrease
Source: Codeforces
Version: Phuoc Hung OJ (single-case adaptation where applicable)
Problem Statement
Given positive integers and an integer , one operation either (1) decreases a chosen element by exactly (negative values allowed), or (2) chooses indices and assigns . Find the minimum operations to make the array sum at most .
Input
The first line contains . The second contains positive integers .
Output
Print the minimum number of operations.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Example 1
Input
1 10
20
Output
10
Explanation
There is only one element; it must be decreased from 20 to 10 in 10 steps.
Example 2
Input
7 8
1 2 1 3 1 2 1
Output
2
Explanation
Assign the element equal to 3 to the value 1, then decrease one occurrence of 1 to 0. Two operations reduce the sum to at most 8.