CHFRICH - Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Practice

Setter: Daanish Mahajan
Tester: Felipe Mota
Editorialist: Aman Dwivedi

DIFFICULTY

Cakewalk

PREREQUISITES

Maths

PROBLEM:

Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth A billion dollars and have no liabilities. He aims to increase his asset by X billion dollars per year.

How much minimum time will it take Chef to be the richest person given he should be worth at least B billion dollars to meet the target.

QUICK EXPLANATION:

Currently, Chef has A billion dollars and he needs at least B billion dollars to become the richest person. Hence the amount that Chef need is :

Amt=B-A

Now, every year Chef increases its asset by X billion dollars. Hence the minimum time that Chef needs to increase its asset by Amt billion dollars is:

time = \left \lceil{\frac{Amt}{x}}\right \rceil

This is the minimum time that Chef needs to become the richest person in Chefland.

TIME COMPLEXITY:

O(1) per test case

SOLUTIONS:

Setter
Tester
Editorialist
#include<bits/stdc++.h>
using namespace std;

#define int long long

void solve()
{
  int a,b,x;
  cin>>a>>b>>x;

  int diff=b-a;

  int ans=diff/x;
  if(diff%x)
    ans++;

  cout<<ans<<"\n";
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int t;
  cin>>t;

  while(t--)
    solve();

return 0;
}

Why was it like this that at the beginning of the contest, problems were different and now they are different. In the beginning, 2 questions were there which were related to graphs and trees and now they arent there

1 Like

True, I found this bug as well.