Un Problema Interesante

 After some fair amount of debugging I got this problem fixed with a better algo, it's a HackerEarth problem.

#include <iostream>

#include<math.h>

#include<stdio.h>

#include<vector>

using namespace std;

int main() {

    // Write C code here

    printf("Hello world");

    cout<<"\n";

    

   int n;

   cin>>n;

   vector<int> a(n),b(n);

   for(int i=0;i<n;i++){

      cin>>a[i];

   }

   for(int j=0;j<n;j++){

      cin>>b[j];

   }

//   for(int x:a){

//       cout<<x<<" ";

//   }

   int min=9549,ind;

   for(int i=0;i<n;i++){

       if(a[i]<min){

           ind=i;

           min=a[i];

       }

   }

   float calc;

   int chk;

   int sum=0;

   int min1=min-b[ind];

   for(int j=0;j<n;j++){

        calc=(a[j]-min)/b[j];

        if((a[j]-(calc*b[j]))==min){

            // cout<<"The elem "<<a[j]<<" is good"<<endl;

            sum+=calc;

        continue;

        }else{

            cout<<"-1";

            return 0;

        }

        // printf("The number of steps are %.2f",calc);

   }

   cout<<"The number of steps are "<<sum<<endl;

    return 0;

}


Comments

Popular Posts