All Tracks Basic Programming Input/Output Basics of Input/Output Problem

Number of steps
Tag(s):

Basic Programming, Basics of Input/Output, Input/Output

Problem
Editorial
Analytics

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

\(1 \le n,\ a_i,\ b_i \le 5000\)

Sample input

2
5 6
4 3

Sample output

-1

SAMPLE INPUT
5
5 7 10 5 15
2 2 1 3 5
SAMPLE OUTPUT
8
Explanation

-

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

February Easy '20

OTHER PROBLEMS OF THIS CHALLENGE
Уведомления
View All Notifications

?