https://codeforces.com/contest/1195/problem/B
想到二分就能做
按照二分吃掉的糖果的话,剩下的糖满足单调性,所以二分可以
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1000000;
typedef long long ll;
ll n,m;
bool check(ll x){
ll ans=0;
for(ll i=1;i<=n-x;i++){//枚举放的个数
ans+=i;
}
ans=ans-x;//最后剩下的
if(ans>=m) return true;
return false;
}
int main(){
while(cin>>n>>m){
int l=0;
int r=inf;
ll ans=inf;
while(l<=r){//二分吃的
ll mid=(l+r)/2;
if(check(mid)){
// cout<<l<<" - "<<r<<endl;
ans=mid;//题中说唯一解
l=mid+1;
}
else{
r=mid-1;
}
}
cout<<ans<<endl;
}
return 0;
}