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 Studio 使用Toast

    Toast 是Android系统中体重的一种非常好的提醒方式 在程序中可以将很小的一段消息提醒给用户 在一段时间后自动消失,不会占用如何屏幕空间 Button button1=(Button) fin ...

  2. c# 对JSON字符串排序(KEY/VALUE)

    public string StortJson(string json) { var dic = JsonConvert.DeserializeObject<SortedDictionary&l ...

  3. echarts X轴显示不全 有省略

    代码如下: xAxis: [ { type: 'category', data: result.weekListAndYear,//result.weekList, axisLabel:{ // in ...

  4. ConstraintLayout使用

    引言 ConstraintLayout是一个ViewGroup,允许您以灵活的方式定位和调整小部件的方法,项目中的布局嵌套问题对项目性能有着不小的威胁,布局能实现扁平化的话会让软件性能得到很大的提升, ...

  5. Lucene的简单用法

    1.创建索引 package com.DingYu.Test; import java.io.File; import java.io.FileInputStream; import java.io. ...

  6. JavaScript中Map和ForEach的区别

    译者按: 惯用Haskell的我更爱map. 原文: JavaScript — Map vs. ForEach - What’s the difference between Map and ForE ...

  7. 解决PHP Redis扩展无法加载的问题(zend_new_interned_string in Unknown on line 0)

    出错代码如下 PHP Warning: PHP Startup: Unable to load 最近在工作中需要使用PHP访问Redis,从https://github.com/phpredis/ph ...

  8. VUE 利用webpack 给生产环境和发布环境配置不同的接口地址

    第一步,分别设置不同的接口地址 首先,我们分别找到下面的文件: /config/dev.env.js /config/prod.env.js 其实,这两个文件就是针对生产环境和发布环境设置不同参数的文 ...

  9. TS学习随笔(二)->类型推论,联合类型

    这篇内容指南:        -----类型推论  -----联合类型 类型推论 第一篇中我们看了TS的基本使用和基本数据类型的使用,知道了变量在使用的时候都得加一个类型,那我们可不可以不加呢,这个嘛 ...

  10. 唯一索引的一种使用情景【有则U无则I】

    这个知识点是最近一位面试老师问我的,当时对这种方法不了解,所以只能说那个中效率低的方法了,也就是先进性select判断,然后在执行更新或者插入操作,显然这种是很麻烦的,也自我反思一下,确实有很多的知识 ...