Number of steps
Practice
2.6 (474 votes)
Basic programming
Input/output
Problem
87% Success 132523 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given two arrays \(a_1, a_2, \dots, a_n\) and \(b_1, b_2, \dots, b_n\). In each step, you can set \(a_i = a_i - b_i\) if \(a_i \ge b_i\). Determine the minimum number of steps that are required to make all \(a\)'s equal.
Input format
- First line: \(n\)
- Second line: \(a_1, a_2, \dots, a_n\)
- Third line: \(b_1, b_2, \dots, b_n\)
Output format
Print the minimum number of steps that are required to make all \(a\)'s equal. If it is not possible, then print -1.
Constraints
\(0 \le n, a_i, b_i \le 5000 \)
Sample input
25 64 3
Sample output
-1
Explanation
-
Code Editor
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
No similar problems found
Editorial
Login to unlock the editorial
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
Results
Custom Input
Run your code to see the output