Untitled
unknown
plain_text
3 years ago
902 B
4
Indexable
Never
#include <iostream> using namespace std; #include<bits/stdc++.h> int main(){ int n; scanf("%d", &n); int a[n-1], b[n-1]; 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;} } }