Meta HackerCup Problem Statement(Running on Fumes)

 // Online C++ compiler to run C++ program online

#include <iostream>

#include<vector>

#define KITTY 23

#define FUNCTION(a,b) a*b

#define MIN(a,b) ((a<b)?a:b)

#define MAX(a,b) ((a>b)?a:b)

using namespace std;


int main() {

    // Write C++ code here

    std::cout << "Hello world!";

    cout<<"Not my first Hello World\n";

    cout<<"The value of Kitty "<<KITTY<<endl;

    cout<<"Using the FUNCTION Macro for FUNCTION(12,12)-->"<<FUNCTION(12,12)<<endl;

    cout<<"Using the MIN Macro for MIN(4,6)--> ";

    cout<<MIN(4,6)<<endl;

    cout<<"Now using the MAX Macro for MAX(4,6)--> "<<MAX(4,6)<<endl;

    

    

    // Meta HackerCup Qualification Problem Statement 

    int test_cases;

    int no_of_cities,fuel_capacity,tank_fuel,total_cost;

    cout<<"Enter the number of test cases please! ";

    cin>>test_cases;cout<<endl;

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

              int chk=0;

        total_cost=0;

        cout<<"Enter the value of no_of_cities please! And then also automatically input the value of fuel_capacity too if you would! ";

        cin>>no_of_cities;cout<<endl;

        cin>>fuel_capacity;

        // cin>>fuel_capacity;

        tank_fuel=fuel_capacity;

        vector<int> city(no_of_cities);

        for(int k=0;k<no_of_cities;k++){

           

            cin>>city[k];cout<<endl;

        }

        //Now moving along the cities in Car with fuel tank having tank capacity as fuel_capacity variable

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

            

            //If there won't be any need to refill the car tank then just exit the loop and return the total_cost as 0

            if(tank_fuel>=no_of_cities){

                break;

            }

            if(city[j+tank_fuel]==0){

              int min_cost=10000;

              for(int l=j;l<tank_fuel+1;l++){

                

                 if((city[l]<min_cost) && (city[l]!=0)){

                     chk=1;

                     min_cost=city[l];

                 }

                }

                if(chk==0){

                   

                    break;

                }

                 

                 tank_fuel=fuel_capacity;

                total_cost=min_cost;   

            }

            

            if(tank_fuel==0){

                tank_fuel=fuel_capacity;

                total_cost+=city[j];

                }

            tank_fuel--;

        }

        if(chk==0){

            

            cout<<"The cost is -1\n";

        }else{

            

     cout<<"The cost for the current test case is "<<total_cost<<endl;

        }

    }

    

    return 0;

}

Comments

Popular Posts