n个床,m个枕头,让第k张床上的枕头最多,相邻床之间枕头差不超过一
二分第k张床上的枕头数,判断是否符合
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAX = 120;
const int mod = 1e9+7;
long long n, m, k;
long long ssum(long long ll, long long kk)
{
long long ans = ll*(kk-ll-1+kk)/2;
if(kk<ll)ans = ll+(kk-1)*(kk-2)/2;
return ans;
}
int main()
{
cin>>n>>m>>k;
long long len1 = k-1, len2 = n-k;
long long low = 1, high = m-n+1, mid, sum1, sum2, ans;
while(low<=high)
{
mid = (low+high)/2;
// cout<<low<<" "<<high<<endl;
// cout<< ssum(len1, mid)<<ssum(len2, mid)<<endl;
sum1 = ssum(len1, mid)+ssum(len2, mid)+mid;
sum2 = n*mid;
// cout<<"sum1="<<sum1<<endl;
if(sum1>m)high = mid-1;
else
{
ans = mid;
low = mid+1;
}
}
cout<<ans<<endl;
return 0;
}