Untitled

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


bool is_integer(float k)
{
    return std::floor(k) == k;
}


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 min = a[0];
        for(int i =0; i<n;i++){
            if(a[i]<min){min = a[i];}
        }

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

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