Last active
August 29, 2015 14:10
-
-
Save ik11235/e739b9aa2013e379d8d1 to your computer and use it in GitHub Desktop.
SRM639
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
class AliceGameEasy { | |
public: | |
long long findMinimumValue(long long x, long long y) { | |
long long ans = 0; | |
long long sum = x+y,r=0,l=3037000490; | |
long long i=(r+l); | |
while(true) | |
{ | |
i=(r+l)/2; | |
if((i*(i+1))/2 == sum) | |
break; | |
else if((i*(i+1))/2 > sum) | |
l=((r+l)/2)-1; | |
else if((i*(i+1))/2 < sum) | |
r=((r+l)/2)+1; | |
if(r>l) | |
return -1; | |
} | |
while(x>0) | |
{ | |
if(x>=i) | |
{ | |
ans++; | |
x-=i; | |
i--; | |
} | |
else | |
{ | |
i=x; | |
} | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment