题意
给定两个序列,可以以任意方式对其重排序,然后每一位求和,求新序列的众数出现次数。
思路
出题人的数据只用了一个(rand()),所以比较大的情况下答案会在32768附近,暴力枚举一下即可。
对于一个枚举的众数(x),答案为(sum_{i=0}^x min(ma[i],mb[x-i]))
(事实证明数据比想象的还要水一点)
代码
#include <bits/stdc++.h>
using namespace std;
namespace StandardIO {
template<typename T>inline void read (T &x) {
x=0;T f=1;char c=getchar();
for (; c<'0'||c>'9'; c=getchar()) if (c=='-') f=-1;
for (; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
x*=f;
}
template<typename T>inline void write (T x) {
if (x<0) putchar('-'),x*=-1;
if (x>=10) write(x/10);
putchar(x%10+'0');
}
}
using namespace StandardIO;
namespace Project {
const int N=100100;
const int INF=2147483647;
int n,ans,maxa,maxb;
int a[N],b[N];
int ma[N],mb[N];
inline void calc (int x) {
int res=0;
for (register int i=0; i<=x; ++i) res+=min(ma[i],mb[x-i]);
ans=max(ans,res);
}
inline void MAIN () {
read(n);
for (register int i=1; i<=n; ++i)
read(a[i]),++ma[a[i]],maxa=max(maxa,a[i]);
for (register int i=1; i<=n; ++i)
read(b[i]),++mb[b[i]],maxb=max(maxb,b[i]);
if (maxa<=5000&&maxb<=5000) for (register int i=5000-60; i<=5000+60; ++i) calc(i);
else for (register int i=32768-23; i<=32768+23; ++i) calc(i);
write(ans);
}
}
int main () {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
Project::MAIN();
}