今天熬夜赶P1650,20分TLE,总是上不去。求哪位大神帮忙看看
#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
#define tab putchar('\t')
#define enter putchar('\n')
#define il inline
#define fi first
#define se second
using namespace std;
int tianji[100001], qiwang[100001];
int n, ans = 0;
bool cmp(int x, int y){
return x > y;
}
int read(){
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-'){
f = -1;
}
c = getchar();
}
while(c >= '0' && c <= '9'){
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
signed main() {
//
cin >> n;
for(int i = 1; i <= n; ++ i){
tianji[i] = read();
}
for(int i = 1; i <= n; ++ i){
qiwang[i] = read();
}
sort(tianji + 1, tianji + 1 + n, cmp);
sort(qiwang + 1, qiwang + 1 + n, cmp);
for(int i = 1, i2 = n, j = 1, j2 = n; i <= i2, j <= j2;){
if(tianji[i] > qiwang[j]){
++ ans;
++ i;
++ j;
}
else if(tianji[i] < qiwang[j]){
-- ans;
++ j;
-- i2;
}
else{
if(tianji[i2] > qiwang[j2]){
++ ans;
-- i2;
-- j2;
}
else{
if(tianji[i2] < qiwang[j])
{
--ans; -- i2; ++ j;
}
}
}
}
cout << 200*ans;
return 0;
}