传送门:Codeforces Round #137 (Div. 2) D
题意:
就说Vasya参加比赛,给出n个项目的比赛成绩,每个项目比两轮,第一行为n和x,x表示Vasya至少得x分,接来下第二行有n个数,表示n个项目第一轮的分数,第三行有n个数,表示n个项目第二轮的分数,项目第一二轮之间的分数随机匹配,求Vasya最好排名和最差排名
假思路:
我一开始以为上下成绩依次配对的。。然后跪了
正确思路:
最优排名就是第一,然后就是找有多少对配对是大于等于x的
做法是把两轮成绩一个顺序排序,一个逆序排序,一个指针 i 从小往大遍历,一个指针 j 从大往小遍历,然后如果在某一时刻指针a[i] + b[j] < x,的话,说明b[j]接下来的也不满足,所以i++,>=x的话,说明a[i]接下来的也会满足,所以j–,i++
代码
#include <algorithm>// ¨|¨|¨| ¨|¨|¨|¨|
#include <iostream>// ¨}¨}¨}¨} ¨~¨~¨~
#include <cstring>// ¨~¨~ ¨~¨~ ¨~¨~
#include <stdio.h>// ¨~¨~ ¨~¨~ ¨~¨~
#include <vector>// ¨~¨~ ¨~¨~ ¨~¨~
#include <cmath>// ¨~¨~ ¨~¨~ ¨~¨~
#include <queue>// ¨~¨~ ¨~¨~¨~¨~ ¨~¨~
#include <map>// ¨~¨~ ¨~¨~ ¨~¨~
using namespace std ;// ¨~¨~ ¨~¨~ ¨~¨~¨~
typedef long long ll;// ¨~¨~ ¨~¨~ ¨~¨~¨~¨~¨~
#define pi pair<int,int> ///
#define P(x,y) make_pair(x,y)
const int maxn = 1e5 + 5;
const ll mod = 998244353;
ll read()
{
ll x=0;char ch=getchar(); bool flag = false;
if(ch=='-') { flag = true; ch = getchar();}
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
if(flag) return -x; else return x;
}
int main()
{ if(fopen("in.txt","r")) freopen("in.txt","r",stdin);
int T,n,m,k,i,sum,j,x,y,t;
scanf("%d%d",&n,&x);
int a[maxn],b[maxn],c[maxn];
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<n;i++) scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+n);
t = 0 , j = n-1;
for(i = 0;i < n;i++){
if(a[i] + b[j] >= x){
t++; j--;
}
}
printf("1 %d\n",t);
return 0;
}