EpifiOA #1
Request Redirection
Estimated HardJudge-ready
Topics (AI-labelled)Binary SearchGreedyTwo Pointers
Assign requests to servers that can serve them. The final load of each server must be strictly less than max_req. Minimize the maximum cross-server distance.
This site's standard input/output format and supplementary bounds are as described in this problem.
Input
The first line contains n (1≤n≤10^5), the second line requests[n], and the third line max_req[n]; all values are non-negative/positive integers ≤10^9. Server positions follow the array indices.
Output
Output the minimum possible maximum redirection distance; output -1 if the total capacity is insufficient.
Example 1
Input:
2
5 0
4 10
Output:
1
Example 2
Input:
3
2 2 0
2 2 5
Output:
1
Example 3
Input:
2
4 4
3 3
Output:
-1
Editorial
Loading solution…