cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)
2 seconds
256 megabytes
standard input
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.
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.
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.
8
1 8 3 11 4 9 2 7
3
7
3 1 7 11 9 2 12
2
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)的更多相关文章
- Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)
A. Technogoblet of Fire 题意:n个人分别属于m个不同的学校 每个学校的最强者能够选中 黑客要使 k个他选中的可以稳被选 所以就为这k个人伪造学校 问最小需要伪造多少个 思路:记 ...
- 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],那么需要要 ...
- 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++ ...
- (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 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- centos7+openvpn+easy3.0
openvpn介绍 OpenVPN 是一个基于 OpenSSL库的应用层 VPN 实现.和传统 VPN 相比,它的优点是简单易用.vpn直译就是虚拟专用通道,是提供企业之间或者公司之间安全数据传输的 ...
- c# 后台分页 jqgrid
/// <summary> /// 获取设备数量 /// </summary> /// <param name="Organid">单位ID&l ...
- mapreduce中文乱码,已解决
问题: mapreduce中文乱码 原因: 再用Hadoop处理数据的时候,发现输出的时候,总是会出现乱码,这是因为Hadoop在设计编码的时候,是写死的.默认是UTF-8,所以当你处理的文件编码格式 ...
- 创建Aurelia项目
什么是Aurelia? Aurelia 是一个新的开源的,基于web标准的mvvm框架,是一个现代化的js模块的集合. Aurelia提供了丰富的plugin,例如国际化,验证,模态框,UI可视化等. ...
- css控制文字自动换行
自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,下面介绍的是CSS如何实现换 行的方法 对于div,p等块级元素正常文字的换行(亚洲文字和非亚洲文字)元素拥 ...
- nodemailer + express + h5 拖拽文件上传 实现发送邮件
一.部署 1.部署Express 2.准备一个邮箱并开始SMTP服务 二.服务器端 三.客户端 四.效果:
- Markdown简单上手
标题 # +内容 一级标题 二级标题 三级标题 四级标题 五级标题 六级标题 字体 1. 加粗(Ctrl+B) **加粗** 2. 斜体(Ctrl+I) *斜体* 3. 斜体加粗(Ctrl+B+I) ...
- Python 标准类库-数据类型之copy-深拷贝浅拷贝操作
标准类库-数据类型之copy-深拷贝浅拷贝操作 by:授客 QQ:1033553122 Python中赋值并不会拷贝对象,只是创建目标和对象的绑定关系. copy.copy(x) 返回x的浅拷贝 ...
- WPF:完美自定义MeaagseBox 2.0
很久前做个一个MessageBox,原文链接:http://www.cnblogs.com/DoNetCoder/p/3843658.html. 不过对比MessageBox还有一些瑕疵.这些天有时间 ...
- cmd输出控制台传递的参数
public class Test2{ public static void main(String[] args){ System.out.println(args[0]); System.out. ...