Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
898 B
12
Indexable
Never
#include <iostream>
using namespace std;
#include<bits/stdc++.h>


int main(){
    int n;
    scanf("%d", &n);
    int a[n], b[n];

    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d", &b[i]);
    }
    int steps=0;

    while(true){
        int max = 0;
        int num;
        for(int i =0; i<n;i++){
            if(a[i]>max){max = a[i];num =i;}
        }
        if(a[num]>b[num]){a[num] = a[num] - b[num];steps++;}

        int bandfail = 0;
        for(int i = 0; i<n;i++){
            if(a[i]<b[i]){bandfail+=1;}
        }
        if(bandfail == n){printf("%d", -1);return 0;}


        int bandpass = 0;
        for(int i =0;i<n-1;i++){
            if(a[i] == a[i+1]){
                bandpass += 1;
            }
        }
        if(bandpass == n-1) {printf("%d", steps); return 0;}


    }
}