1. 程式人生 > >Educational Codeforces Round 52 (Rated for Div. 2)B. Vasya and Isolated Vertices·「模擬,思維」

Educational Codeforces Round 52 (Rated for Div. 2)B. Vasya and Isolated Vertices·「模擬,思維」

B. Vasya and Isolated Vertices

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條邊,問把這n個點連線起來最後最多剩下多少個孤立點,最少剩下多少個孤立點。

大致思路:我們知道,要想把n個點全部連線起來最多需要n (n + 1) / 2條邊,所以我們可以逐個去掉n個點的每一個點,再在剩下的點裡面按最多的邊連邊,最後看剩下多少個點。然後我們在來考慮剩下最少的點,要想保證最後剩下的點最少,我們就要使每個邊儘可能多的連點,也就是說讓一條邊只連線兩個點,每個點只有一條邊相連,所以我們讓m條邊都連上點,最後在和0取最大值。

talk is cheap ,show me the code! .

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
	ll n,m;
	while(~scanf("%lld %lld",&n,&m)){
		ll minn,maxx;
		minn = n;
		maxx = -1;
		for(ll i = 0; i <= n; i++){
			ll k = n - i;
			k = k * (k - 1) / 2;
			if(k >= m) maxx = max(i,maxx);
		}
		while(m){
			m--;
			minn -= 2;
		}
		printf("%lld %lld\n",max(minn,0*1LL),maxx);
	}
	return 0;
}