[bzoj1034][ZJOI2008]泡泡堂BNB【贪心】

【题目链接】
  http://www.lydsy.com/JudgeOnline/problem.php?id=1034
【题解】
  现将两个序列排好序。来考虑B的最大收益。
  记A,b剩余数列的左右端点。
  若]则选择这两个打(最小的打最小的)。
  若]则选择这两个打(最大的打最大的)。
  否则用]消耗。
  有一个点我一开始一直想不通,为什么1分。
  解答是:因为当前]打。YY一下感觉很有道理。
  

/* --------------
    user Vanisher
    problem bzoj-1034
----------------*/
# include <bits/stdc++.h>
# define    ll      long long
# define    inf     0x3f3f3f3f
# define    N       100010
using namespace std;
int read(){
    int tmp=0, fh=1; char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') fh=-1; ch=getchar();}
    while (ch>='0'&&ch<='9'){tmp=tmp*10+ch-'0'; ch=getchar();}
    return tmp*fh;
}
int a[N],b[N],n;
int solve(int *a, int *b){
    int pl1=1, pr1=n, pl2=1, pr2=n, num=0;
    while (pl1<=pr1){
        if (a[pl1]>b[pl2]){
            pl1++, pl2++, num+=2;
            continue;
        }
        if (a[pr1]>b[pr2]){
            pr1--, pr2--, num+=2;
            continue;
        }
        if (a[pl1]==b[pr2])
            num++;
        pl1++, pr2--;
    }
    return num;
}
int main(){
    n=read();
    for (int i=1; i<=n; i++) a[i]=read();
    for (int i=1; i<=n; i++) b[i]=read();
    sort(a+1,a+n+1); sort(b+1,b+n+1); 
    int ans1=solve(a,b), ans2=n*2-solve(b,a);
    printf("%d %d
",ans1,ans2);
    return 0;
}