Computer Network
면접 대비시간 제한1초메모리 제한2048 MB
배열 a 전체에 +1을 더하거나 2로 나눈 몫을 취하는 연산만으로 a를 b로 바꾸는 최소 횟수를 구하고, 불가능하면 -1을 출력한다.
문제
The additive-increase/multiplicative-decrease (AIMD) algorithm is a feedback control algorithm best known for its use in TCP congestion control. AIMD combines linear growth of the congestion window when there is no congestion with an exponential reduction when congestion is detected. Multiple flows using AIMD congestion control will eventually converge to an equal usage of a shared link. (from Wikipedia)
You are given two arrays of integers: and . You can perform operations on the array . In one operation, you can let become for all , or let become for all .
Find the minimum number of operations that you have to perform to transform into , or determine that it is impossible.
입력
The first line contains an integer ().
The second line contains the integer array ().
The third line contains the integer array ().
출력
Print the minimum number of operations needed, or if it's impossible to transform into .