A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers — the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 ≤ bi ≤ 105) — the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad — there are two integers i, j (1 ≤ i, j ≤ n) such, that ai + bj ≥ x.
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
5 2 1 1 1 1 1 1 1 1 1 1
1 5
6 7 4 3 5 6 4 4 8 6 0 4 3 4
1 5
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that — {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that — {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
题意:n个人参加了两场比赛。已知第一场比赛所有人分别得的分数(不知一个分数具体是谁得的)和第二场比赛所有人的得分数(同样不知道得分人具体是谁)。人的总得分为该人两场比赛得分的总和。已知有一个人最少得了x分,问一个人有可能的最好排名和最坏排名。(如果两个人总得分相同,那么他们之间排名什么都有可能)。
题意:最好排名显然是第1。至于求最坏排名,实际是就是求最多有多少个人的得分大于等于x。我们可以枚举一个人在第一场比赛中的得分a,然后贪心的在第二场比赛的中找最小的得分b,使得(a+b)>=x(可以用multiset来实现)。
代码如下:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<stdlib.h>
#include<vector>
#define inff 0x3fffffff
#define nn 110000
#define mod 1000000007
typedef long long LL;
const LL inf64=inff*(LL)inff;
using namespace std;
int n,x;
int a[nn],b[nn];
multiset<int>se;
multiset<int>::iterator it;
int main()
{
int i;
while(scanf("%d%d",&n,&x)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
se.clear();
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
se.insert(b[i]);
}
int ans=0;
for(i=1;i<=n;i++)
{
it=se.lower_bound(x-a[i]);
if(it!=se.end())
{
ans++;
se.erase(it);
}
}
printf("1 %d\n",ans);
}
return 0;
}