Different Rules CodeForces - 1313B(思维)

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
唉,这个B题真的狗啊。感觉比c题难多了。。
思路:
①对于最差的情况,我们只要尽可能多的构造和x+y相等的情况就行,因为是看4 4 4并不是并列第1,而是并列第3。所以我们假设从第一个人开始,第一轮的成绩分别是:1,2,3,4…x+y-1,第二个人的成绩分别是:x+y-1,x+y-2…1,这样贪心的话,情况就是最糟糕的。
②对于最好的情况,我们尽可能的让其他的人得分高。假设x+y<=n的,那么我们假设从第一个人开始第一轮得分依次是:1,2,3…n,那么第二轮开始得分是n,n-1,n-2…1,这样每个人最高得分n+1。如果x+y>n的话,那么我们让第一名两轮都得第一,这样名次都提前一名,分别是x-1,y-1。我们一直这么做,一直到第一种情况,x-t+y-t=n-t即x+y-n=t,就代表着前面有x+y-n个人,那么就是x+y-n+1名。注意边界情况。
代码如下:

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

ll n,x,y;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld%lld",&n,&x,&y);
		printf("%lld %lld\n",min(n,max(1ll,(ll)(x+y-n+1))),min((ll)(x+y-1),(ll)n));
	}
	return 0;
}

努力加油a啊,(o)/~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值