time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has got an undirected graph consisting of nn vertices and mm edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges (1,2)(1,2) and (2,1)(2,1) is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex.
Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of nn vertices and mm edges.
Input
The only line contains two integers nn and m (1≤n≤105,0≤m≤n(n−1)2)m (1≤n≤105,0≤m≤n(n−1)2).
It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges.
Output
In the only line print two numbers minmin and maxmax — the minimum and maximum number of isolated vertices, respectively.
Examples
input
Copy
4 2
output
Copy
0 1
input
Copy
3 1
output
Copy
1 1
Note
In the first example it is possible to construct a graph with 00 isolated vertices: for example, it should contain edges (1,2)(1,2) and (3,4)(3,4). To get one isolated vertex, we may construct a graph with edges (1,2)(1,2) and (1,3)(1,3).
In the second example the graph will always contain exactly one isolated vertex.
题意
给你n个点,m条边,让你找最多孤立点和最少孤立点,不能有自环路
分析
对于最少max(0,n-2*m),
然后考虑独立点最多的情况:也就是说我们要考虑使每条边的利用效率最低。
等同于可以这样想:加入每个点,使这个点消耗的边最多,一直添加到没有变剩余为止。
我们可以在新的点加入时,将其连接到所有已经不是独立点的点上,这样就能最多的消耗边。
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,m,ans1,ans2;
int main(){
scanf("%lld%lld",&n,&m);
if(m==0){
ans1=ans2=n;
}
else{
ans1=n-(m*2);
if(ans1<0)ans1=0;
int i=1;
while(m>0){
m-=i;
i++;
}
ans2=n-i;
}
printf("%lld %lld",ans1,ans2);
return 0;
}