Codeforces Round #622 (Div. 2) B题

B. Different Rules
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.

Suppose in the first round participant A took x-th place and in the second round — y-th place. Then the total score of the participant A is sum x+y. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every i from 1 to n exactly one participant took i-th place in first round and exactly one participant took i-th place in second round.

Right after the end of the Olympiad, Nikolay was informed that he got x-th place in first round and y-th place in the second round. Nikolay doesn’t know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

Input
The first line contains an integer t (1≤t≤100) — the number of test cases to solve.

Each of the following t lines contains integers n, x, y (1≤n≤109, 1≤x,y≤n) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Output
Print two integers — the minimum and maximum possible overall place Nikolay could take.

Examples
input
1
5 1 3
output
1 3
input
1
6 3 4
output
2 6
题意:
就是一个人参加两场比赛,这两场比赛都有n个人,每场比赛都有一个排名,两场比赛的排名相加,即为最终的分,他的最终排名为比他小的人数加上他自己,即比他小的人数加一。题目给出这个人在这两场比赛中的排名,和参加比赛的人数。要求出他的最好排名和最差排名。
思路:
我们可以先找出他的最差排名,如果想使他的排名靠后,那么我们需要让尽可能多的人排在他的前面,那么就让尽可能多的人和他相等,假设这个人在第一场中排n名x,第二场中排名y,那么他的得分是x+y,那么我们可以让第一场中的第一名在第二场中排名x+y-1,第2名在第二场排x+y-2,依次类推,当到第一场排到x+y名时,就不可能比这位参赛者相等了,所以他的最差排名为min(n,x+y-1)。
接着我们再来找最好排名,如果想要排的靠前,那么我们就需要让尽可能少的人排在这位参赛者的前面,那么我们仍然假设他在第一场中排x名,在第二场中排y名,此时我们需要分情况讨论,如果x+y<=n,那么我们为了使他排的靠前,就需要别人靠后,我们可以假定第一场中的第1名在第二场排第n名,然后第一场的第2名在第二场排n-1名,因此总是可以得到排名为n+1,所以此时该参赛者可以得第1名,当x+y>n时,第一场中的第1名无论如何构造都要比该参赛者靠前,那么我们为了让他前面的人尽可能少,就要让第一场中的第1名与第二场中的第1名匹配,然后依次类推,使得尽可能的消耗排名靠前的位次,每匹配依次相当于x-=1,y-=1,n-=1,那么假设匹配t次可以得到x-t+y-t<=n-t实现,那么我们解出最小的t为x+y-n
此时为不算该参赛者,加上该参赛者为x+y-n+1。
实现代码:

#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int t,n,x,y;
int main() {
	cin>>t;
	while(t--){
		cin>>n>>x>>y;
		cout<<max(1,min(n,x+y-n+1))<<" "<<min(n,x+y-1)<<endl;
	}
	
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值