简单的模拟题
就是一开始没看懂标程
标程:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long m;
cin >> n >> m;
long long cur = 1;
long long rem = m;
//表示的是大于m的最小符合n*(n-1)/2的n
while(rem > 0){
long long d = min(cur, rem);
rem -= d;
++cur;
}
assert(rem == 0);
long long res = n;
if(cur > 1) res = n - cur;
cout << max(0ll, n - m * 2) << ' ' << res << endl;
return 0;
}
法二:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m;
int main()
{
cin >> n >> m;
cout << max(n-2*m,0LL) << " ";
if(m == 0)
{
cout << n << endl;
return 0;
}
for(ll i = 1; i <= n; i++)
{
if(m <= i*(i-1)/2)
{
cout << n-i << endl;
return 0;
}
}
return 0;
}