题意:田忌和齐王有n匹马,进行n局比赛,每局比赛输者给胜者200,问田忌最多能得多少钱。
分析:如果田忌最下等的马比齐王最下等的马好,是没必要拿最下等的马和齐王最好的马比的。(最上等马同理)
因此,如果田忌最下等的马>齐王最下等的马或者田忌最上等的马>齐王最上等的马,直接得200,如果不满足该条件,那么才让田忌最下等的马与齐王最上等的马来比。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, };
const int dc[] = {-, , , };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
deque<int> a, b;
int main(){
int n;
while(scanf("%d", &n) == ){
if(n == ) return ;
a.clear();
b.clear();
int x;
for(int i = ; i < n; ++i){
scanf("%d", &x);
a.push_back(x);
}
for(int i = ; i < n; ++i){
scanf("%d", &x);
b.push_back(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = ;
while(n--){
if(a.front() > b.front()){
ans += ;
a.pop_front();
b.pop_front();
}
else if(a.back() > b.back()){
ans += ;
a.pop_back();
b.pop_back();
}
else{
if(a.front() < b.back()){
ans -= ;
a.pop_front();
b.pop_back();
}
}
}
printf("%d\n", ans);
}
return ;
}