solution-cf1121b

简单题

所以,因为 $a_i$ 互不相同,所以发现对于一种数的和 $k$,只有唯一的一对 $a_i+a_j=k$,因此不用考虑选数产生后效性。考虑开一个桶记录每个和出现的次数,最终取最大值即可。

// Problem: Mike and Children
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF1121B
// Memory Limit: 250 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 1e4+10;
int a[MAX];
map <int, int> f;
void solve(){
    int n = read();
    for(int i = 1; i <= n; i++) a[i] = read();
    for(int i = 1; i <= n; i++) for(int j = i + 1; j <= n; j++) f[a[i] + a[j]] ++;
    int maxn = 0;
    for(int i = 1; i <= n; i++) for(int j = i + 1; j <= n; j++) maxn = max(maxn, f[a[i] + a[j]]);
    write(maxn), endl;
}

signed main(){
    int t = 1;
    while(t--)  solve();
    return 0;
}
posted @ 2023-05-12 18:56  WRuperD  阅读(0)  评论(0编辑  收藏  举报  来源

本文作者:DIVMonster

本文链接:https://www.cnblogs.com/guangzan/p/12886111.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

这是一条自定义内容

这是一条自定义内容