您的位置:首页 > 其它

codeforces 785D

2017-03-16 21:12 288 查看
http://codeforces.com/problemset/problem/785/D

#include <bits/stdc++.h>
#define maxs 20202
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
char s[maxs];
#define ll long long

int main()
{
ll n,m;
while(cin>>n>>m)
{
if(n<=m)
{
cout<<n<<endl;
continue;
}

n-=(m+1);

if(n<=0)
{
cout<<m+1<<endl;
continue;
}

ll l=0,r=2e10+3;
ll cost,mid,t=0,ans=m;

while( l<=r )
{
mid = ( l+r )>>1;
cost = ( mid+2 )*( mid-1 )/2;
if(cost>=n)
{
t=mid;
r=mid-1;
}
else
l=mid+1;
}
ans+=t;
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: