B. Mike and Children
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.

Mike has nn sweets with sizes a1,a2,…,ana1,a2,…,an . All his sweets have different sizes. That is, there is no such pair (i,j)(i,j) (1≤i,j≤n1≤i,j≤n ) such that i≠ji≠j and ai=ajai=aj .

Since Mike has taught for many years, he knows that if he gives two sweets with sizes aiai and ajaj to one child and akak and apap to another, where (ai+aj)≠(ak+ap)(ai+aj)≠(ak+ap) , then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset.

Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can.

Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset.

Input

The first line contains one integer nn (2≤n≤10002≤n≤1000 ) — the number of sweets Mike has.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105 ) — the sizes of the sweets. It is guaranteed that all integers are distinct.

Output

Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset.

Examples
Input

Copy
8
1 8 3 11 4 9 2 7
Output

Copy
3
Input

Copy
7
3 1 7 11 9 2 12
Output

Copy
2
Note

In the first example, Mike can give 9+2=119+2=11 to one child, 8+3=118+3=11 to another one, and 7+4=117+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution.

In the second example, Mike can give 3+9=123+9=12 to one child and 1+111+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.

这个题目,其实不太难,但是我自己还是没有独立解决,水平严重有待提升,这个呢要注意n个数都互不相等的,所以这说明要是求出相等的,则肯定不会用到同一个数  (a[i]+a[j]==a[i]+a[k]不可能成立)

知道这个我就会写了,就直接二重循环即可

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1300;
const int inf=2e5+10;
int p[inf];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,a[maxn];
ll ans=0;
memset(p, 0, sizeof(p));
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
{
for (int j = i+1; j <= n; j++)
{
p[a[i] + a[j]]++;
ans=max(1ll*p[a[i]+a[j]],ans);
} }
printf("%d\n",ans);
return 0;
}

  

cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)的更多相关文章

  1. Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)

    A. Technogoblet of Fire 题意:n个人分别属于m个不同的学校 每个学校的最强者能够选中 黑客要使 k个他选中的可以稳被选 所以就为这k个人伪造学校 问最小需要伪造多少个 思路:记 ...

  2. Codeforces Round #543 (Div. 1, based on Technocup 2019 Final Round) 题解

    题面戳这里 A. Diana and Liana 首先如果s>ks>ks>k一定无解,特判一下.那么我们考虑找恰好满足满足题目中的要求的区间[l,r][l,r][l,r],那么需要要 ...

  3. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  4. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  7. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  8. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

  9. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup

    The last stage of Football World Cup is played using the play-off system. There are n teams left in ...

随机推荐

  1. [android] 保存文件到SD卡

    /****************2016年5月4日 更新*****************************/ 知乎:为什么很多Android应用要把文件写到/sdcard目录下而不是写到/d ...

  2. springboot用户登陆密码两次md5加密

    1.用户端:PASS = MD5(明文 + 固定salt) 2.服务端:PASS = MD5(用户输入 + 随机salt) 引入依赖包 <dependency> <groupId&g ...

  3. Word转MD文件

    直接把网页的内容复制,丢进下面的网站,转为html格式,复制html代码文本 WordHtml 把代码文本放在这里 Html转MD

  4. 《Unix网络编程》读书笔记

    UDP和TCP UDP(User Datagram Protocol,用户数据报协议)是一个无连接协议,不保证UDP数据报会到达其最终目的地,不保证各数据报的先后顺序跨网络后保持不变,也不保证每个数据 ...

  5. ASPxGridView 用法

    一.ASPxGridView属性:概述设置(Settings) 1.1.Settings <Settings GridLines="Vertical" : 网格样式 Vert ...

  6. php使用fullcalendar日历插件

    最近做课程表的项目,找了好多个插件感觉都不好用,无意间看到了fullcalendar,还挺简单的,很方便,先贴一张项目页面 <!DOCTYPE html> <html> < ...

  7. canvas实现黑客帝国矩形阵

    在博客园看到了车大棒的写了一篇关于实现黑客帝国矩形阵,觉得canvas还是有一些奇妙的地方所在,故做个笔记记录一下. 实现的效果如下: 真的是一两行关键的代码添加就能实现意想不到的效果. 由于是can ...

  8. agc002E - Candy Piles(博弈论)

    题意 题目链接 Sol Orz SovitPower #include<bits/stdc++.h> #define Pair pair<int, double> #defin ...

  9. 18.Odoo产品分析 (二) – 商业板块(10) – 电子商务(2)

    查看Odoo产品分析系列--目录 接上一篇Odoo产品分析 (二) – 商业板块(10) – 电子商务(1) 6. 高级属性 除了我们到目前为止已经覆盖基本选项,Odoo在产品页面还提供了一些高级选项 ...

  10. C# 动态加载程序集信息

    本文通过一个简单的实例,来讲解动态加载Dll需要的知识点.仅供学习分享使用,如有不足之处,还请指正. 在设计模式的策略模式中,需要动态加载程序集信息. 涉及知识点: AssemblyName类,完整描 ...