Created
October 30, 2016 07:07
-
-
Save ia7ck/0a58deb601940b3f2955f084c5a231b1 to your computer and use it in GitHub Desktop.
ARC 050-B 花束
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
#define int long long | |
int R, B, x, y; | |
int cal(int k){ | |
int r=(R-k), b=(B-k); | |
if(r<0||b<0) return -1; | |
r=r/(x-1); b=b/(y-1); | |
return r+b; | |
} | |
signed main(){ | |
cin>> R>> B>> x>> y; | |
int l=0, h=1e18+1; | |
// h=min(R, B)+1にすると、cal()の中でのr<0, b<0の判定が不要に | |
while(h-l>1){ | |
int md=(l+h)/2; | |
if(cal(md)>=md) l=md; | |
else h=md; | |
} | |
printf("%lld\n", l); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment