Chef and Stones - CHEFSTON CodeChef Easy Question

Hope , everyone is having a good time on my blog .
Welcome back to our journey with a new question for you.
Here is the link to today' PROBLEM

The problem is very straightforward and simple and has no prerequisites to be solved .

The solution is simple , you just need to iterate over all the stone kinds and check his profit . When you find the maximum till now , store it in variable max.
In the end max will contain maximum profit and your problem is solved .
This solution is of O(n) time complexity and fits in the constraints given .

Just take a look at the following C++ code to understand the solution better .

#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--)
    {
    unsigned long long int n,k,ans=0,max=0;
    cin>>n>>k;
    long long int arr[n],arr1[n];
    int i=0;
    while(i!=n)
    {
        cin>>arr[i];
        i++;
    }
    i=0;
    while(i!=n)
    {
        cin>>arr1[i];
        i++;
    }
    i=0;
    while(i!=n)
    {
        ans=arr1[i]*(k/arr[i]);
        if(ans>max)
        {
            max=ans;
        }
        i++;
    }
    cout<<max<<endl;
    }
// your code goes here
return 0;
}



Do leave your doubts and queries in the comments section.
And do not forget to follow and subscribe this blog.

Comments

Popular Posts