Practice

Contest: Division 1

Contest: Division 2

Contest: Division 3

**Author:** Daanish Mahajan

**Tester:** Manan Grover

**Editorialist:** Aman Dwivedi

# DIFFICULTY:

Cakewalk

# PREREQUISITES:

None

# PROBLEM:

Chef is a very lazy person. Whatever work is supposed to be finished in x units of time, he finishes it in m∗x units of time. But there is always a limit to laziness, so he delays the work by at max d units of time. Given x,m,d find the maximum time taken by Chef to complete the work.

# EXPLANATION:

As we can see the upper bound to complete the work is fixed, i.e Chef cannot delay the work beyond this time. The upper bound for any work x is x+d since he cannot delay any work by more than d units of time.

Also, it is given that any work that is assigned to Chef which is supposed to be finished in x units of time, he will finish that in x*m units of time.

As we need to find the maximum time taken by Chef to complete the work, there will be two cases possible:

**Case 1:** x+d \ge m*x

- In this case, Chef can finish the work assigned to him in m*x units of time, which is less than the upper bound of the time to finish the work. Hence the maximum time by Chef to complete the work, in this case, will be m*x.

**Case 2:** x+d < m*x

- In this case, the upper bound to finish the work by Chef is less than the maximum time he used to take to finish the work assigned to him. Hence, the maximum time Chef can take to complete the work assigned to him is x+d in this case.

# TIME COMPLEXITY:

O(1) per test case

# SOLUTIONS:

## Setter

```
#include<bits/stdc++.h>
# define pb push_back
#define pii pair<int, int>
#define mp make_pair
# define ll long long int
using namespace std;
const int maxt = 1e4, maxn = 10, maxm = 10, maxd = 99;
const string newln = "\n", space = " ";
int main()
{
int t; cin >> t;
int x, m, d;
while(t--){
cin >> x >> m >> d;
cout << min(x * m, x + d) << endl;
}
}
```

## Tester

```
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
while(t--){
int x,m,d;
cin>>x>>m>>d;
int ans = min(x * m, x + d);
cout<<ans<<"\n";
}
return 0;
}
```

## Editorialist

```
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int x,m,d;
cin>>x>>m>>d;
cout<<min(x*m,x+d)<<"\n";
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
```