You are a top-class competitive programmer with a brilliant mind and deep…
- User
Prompt:
You are a top-class competitive programmer with a brilliant mind and deep insight. Solve the following extremely difficult problem.
Analyze the problem in detail: Read the problem and clarify the key points, constraints, and the problem to be solved. Consider various approaches: Propose multiple possible approaches to solve the problem and consider the advantages and disadvantages and applicability of each. Design the optimal algorithm: Use your deep insight to design an efficient and optimal algorithm. Use advanced data structures, algorithms, and mathematical techniques as necessary. Implement the code: Implement the selected algorithm in high-quality code. It is preferable that the code is easy to read and optimized. Detailed explanation of your thought process: Explain in detail the thought process and reasoning that led to the solution, as well as any changes in thinking. Apply an original perspective: Think outside the box and actively incorporate original perspectives and innovative ideas. [Problem Statement There is an octopus-shaped robot and N treasures on a number line. The i-th treasure (1≤i≤N) is located at coordinate X i . The robot has one head and N legs, and the i-th leg (1≤i≤N) has a length of L i .
Find the number of integers k such that the robot can grab all N treasures as follows.
Place the head at coordinate k. Repeat the following for i=1,2,…,N in this order: if there is a treasure that has not been grabbed yet within a distance of L i from the head, that is, at a coordinate x satisfying k−L i ≤x≤k+L i , choose one such treasure and grab it. Constraints 1≤N≤200 −10 18 ≤X 1 <X 2 <⋯<X N ≤10 18
1≤L 1 ≤L 2 ≤⋯≤L N ≤10 18
All input values are integers. Input The input is given from Standard Input in the following format:
N X 1
X 2
… X N
L 1
L 2
… L N
Output Print the number of integers k that satisfy the condition in the statement.
Sample Input 1 Copy 3 -6 0 7 3 5 10 Sample Output 1 Copy 6 k=−3,−2,−1,2,3,4 satisfy the condition. For example, when k=−3, the robot can grab all three treasures as follows.
The first leg can grab treasures at coordinates x satisfying −6≤x≤0. Among them, grab the first treasure at coordinate −6. The second leg can grab treasures at coordinates x satisfying −8≤x≤2. Among them, grab the second treasure at coordinate 0. The third leg can grab treasures at coordinates x satisfying −13≤x≤7. Among them, grab the third treasure at coordinate 7. Sample Input 2 Copy 1 0 1000000000000000000 Sample Output 2 Copy 2000000000000000001 All integers k from −10 18 to 10 18 satisfy the condition.
Sample Input 3 Copy 2 -100 100 1 1 Sample Output 3 Copy 0 No k satisfies the conditions.]
- Assistant