ThoughtspotOA #1
Get Minimum Time
估计中等可在线判题
The system has services numbered 1 to n and must handle m requests. Request i is cached on service cache[i]. Each request can be assigned to any one service: if it goes to its cache service, processing takes 1; otherwise it takes 2. Different services can work in parallel, but one service can process only one request at a time. All requests can be scheduled starting from time 0, with no arrival times or task dependencies. Find the shortest time needed to process all requests. The wrong algorithm of the compiled version, which only counts the maximum cache frequency, is not adopted.
输入格式
The first line contains n and m. The second line contains m integers cache[i]. 1≤n,m≤100000, 1≤cache[i]≤n.
输出格式
Output one integer: the shortest time to complete all requests.
样例 1
输入:
3 5
1 1 3 1 1
输出:
3
样例 2
输入:
3 1
2
输出:
1
样例 3
输入:
2 4
1 1 1 1
输出:
3
样例说明
Example 1 keeps the original input and output and fixes a service-number typo in the original explanation: service 1 processes requests 1, 2, and 4 in time 3; service 3 processes request 3 in time 1; service 2 processes request 5 in time 2; everything finishes within 3. Examples 2 and 3 are added by this site: a single request takes 1 on its cache service; when all four requests are cached on service 1, service 1 can process three of them and service 2 one, for a total time of 3.