[Explanations] BZOJ1034 [ZJOI2008] BNB BNB (greedy)
Consider direct analog Tian Ji's horse ...
- My smallest than your big, directly on the
- My biggest than your big, directly on the
- otherwise, my little big change you
Consider the worst, since each game is generated and only produces \ (2 \) points, and then outputs the two arrays so swap \ (2n-ans \) can.
Note that when implemented within a cycle can only be generated once the competition, or may cause a person to repeat the game twice ...
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
const int maxn=1e6+5;
int data1[maxn],data2[maxn],n;
inline int getp(const int&x,const int&y){
if(x>y)return 2;
if(x==y)return 1;
return 0;
}
inline int getans(int*a,int*b){
int L1=1,L2=n,R1=1,R2=n,ret=0;
while(L1<=L2&&R1<=R2){
if(a[L2]>b[R2]) ret+=2,L2--,R2--;
else if(a[L1]>b[R1]) ret+=2,L1++,R1++;
else ret+=(a[L1]==b[R2]),L1++,R2--;
}
return ret;
}
int main(){
n=qr();
for(int t=1;t<=n;++t)data1[t]=qr();
for(int t=1;t<=n;++t)data2[t]=qr();
sort(data1+1,data1+n+1);
sort(data2+1,data2+n+1);
printf("%d %d\n",getans(data1,data2),2*n-getans(data2,data1));
return 0;
}