【链接】 我是链接,点我呀:)
【题意】
【题解】
枚举三分线(离散后)的位置 然后根据预处理的前缀和,快速算出两个队伍的分数。【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n,m;
int a[N+10],b[N+10],aa[2*N+100],bb[2*N+100];
map<int,int> dic;
map<int,int> dic2;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> a[i];
dic[a[i]] = 1;
}
cin >> m;
for (int i = 1;i <= m;i++) {
cin >> b[i];
dic[b[i]] = 1;
}
map<int,int>::iterator it;
int cnt = 0;
dic2[0] = ++cnt;
for (it = dic.begin();it!=dic.end();it++) {
dic2[(*it).first] = ++cnt;
}
for (int i = 1;i <= n;i++){
aa[dic2[a[i]]]++;
}
for (int i = 1;i <= m;i++){
bb[dic2[b[i]]]++;
}
for (int i = 1;i <= cnt;i++) aa[i]+=aa[i-1];
for (int i = 1;i <= cnt;i++) bb[i]+=bb[i-1];
int ans = -(1e8),maxa;
for (int i = 1;i <= cnt;i++){
int ga = aa[i]*2+(n-aa[i])*3;
int gb = bb[i]*2+(m-bb[i])*3;
if (ga-gb>ans){
ans = ga-gb;
maxa = ga;
}else if (ga-gb==ans){
if (maxa<ga){
maxa = ga;
}
}
}
cout<<maxa<<":"<<maxa-ans<<endl;
return 0;
}