PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000160. Tối đa tần suất bằng phép tăng giảm (Apply Operations to Maximize Frequency Score)
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 tần suất bằng phép tăng giảm (Apply Operations to Maximize Frequency Score)
Apply Operations to Maximize Frequency Score
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers and a budget , you may increment or decrement one chosen element by exactly in each operation, performing at most operations. The score of the resulting array is the maximum frequency of any value. Find the greatest possible score.
Input
- The first line contains .
- The second line contains integers .
Output
Print the largest achievable frequency after at most operations.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
4 3
1 2 6 4
Output
3
Explanation
With and , raise to (one operation), and lower to (two operations). This yields , so the answer is 3. Making all four elements equal would require more than three operations.