yashgulani's blog

By yashgulani, history, 5 years ago, In English

Why double coins = (double)(k+l)/m and then ceil(coins) works

And this one faila for case 28

ll long long int main() { ll n,m,k,l; cin>>n>>m>>k>>l;

ll coins = ceil((double)(k+l)/m);

if(k+l > n || coins*m > n)
{
    cout<<"-1"<<endl;
}
else {
    cout<<coins<<endl;
}
//main();

}

Thanks in advance

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by yashgulani (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by yashgulani (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Always try to stick to integers.

In this case it's equivalent (mathematically) to ll coins = (k+l+m-1)/m;

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I faced the same problem. But it's working fine with long double.