Architect's Dilemma..!
Practice
4.8 (12 votes)
Binary search
Easy
Greedy algorithms
Hiring
Sorting
Problem
73% Success 3356 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

An Architect has been assigned a project and some number of workers work for him. Each of the workers is assigned a fixed amount of work. Suddenly, he has been appointed to build a new elegant office by the mayor. He won't disappoint mayor and finish the task as quickly as possible.
Now, the architect has some amount of extra work to build the new office. He wants to assign this extra work to workers in such a way that there are maximum number of workers with same amount of total work. It might not be possible to give equal amount of work to each worker. He wants to find maximum number of workers possible with same amount of total work. It is not necessary that architect assigns all of his extra work.

Input Format:

First line has two integers N , number of workers and W , amount of extra work architect has.
The second line contains N integers separated by single space, \(a_1, a_2, .... ,a_n\) where \(a_i\) is the amount of fixed work \(i^{th}\) worker has.

Output Format:

Output maximum number of workers that have equal amount of total work.

Input Constraints:
\(1\le N \le 10^5\)
\(1 \le W \le 10^7\)
\(1 \le a_i \le 10^6\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
21 votes
Tags:
ApprovedBasic ProgrammingEasyGreedy AlgorithmsOpen
Points:20
16 votes
Tags:
Ad-HocAlgorithmsBasic ProgrammingEasyGreedy Algorithms
Points:20
390 votes
Tags:
ApprovedBrute-force searchEasyGreedy AlgorithmsOpenSorting