# Need help in Codeforces  Carrot Cakes

**URL:** <https://discuss.codechef.com/t/need-help-in-codeforces-carrot-cakes/19157>\
**Category:** general\
**Tags:** codeforces\
**Created:** [June 24, 2018, 4:11pm UTC](https://discuss.codechef.com/t/need-help-in-codeforces-carrot-cakes/19157 "2018-06-24T16:11:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![meet2mky](https://discuss.codechef.com/user_avatar/discuss.codechef.com/meet2mky/32/51944_2.png) [@meet2mky](https://discuss.codechef.com/u/meet2mky)\
**Post date:** [June 24, 2018, 8:46pm UTC](https://discuss.codechef.com/t/need-help-in-codeforces-carrot-cakes/19157/2 "2018-06-24T20:46:51Z")

</div>

let’s say we don’t build second one.

Then it’s just simple to calculate **TimeWithoutBuild** using formula :

_TimeWithoutBuild = ceil(n/k) t_\*

Now let’s build the second and calculate the **TimeWithBuild** :

as it take **d** unit time to build, we first add **d** to **TimeWithBuild** now we might have already baked some cakes while building the second one. So we need to subtract that cakes from **n** , so our remaining cakes will be \*_n-(d/t)k_ let’s say this is **n\_rem** Now our speed of baking is doubled  
So

**TimeWithBuild = d + ceil(n\_rem/(2\*k)) \* t**

Now you will be good to code it yourself but nevertheless here is my solution…  
Good Luck 😛

[details=Click to view]

```
#include
using namespace std;
#define int long long
signed main(){
    int n,t,k,d;
    cin >> n >> t >> k >> d;
    int T1 = t*( (n/k) + (n%k!=0));
    int T2 = d + t*(( n-(d/t)*k )/(2*k) +(( n-(d/t)*k )%(2*k)!=0));
    if(T2 < T1)puts("YES");
    else puts("NO");
    return 0;
}
```

---

_[View the full topic](https://discuss.codechef.com/t/need-help-in-codeforces-carrot-cakes/19157)._
