Untitled

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


int main(){
    int n;
    cin>>n;
    int a[n], b[n];

    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>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){cout<<-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) {cout<<steps; return 0;}

    }
}