102722: [AtCoder]ABC272 C - Max Even

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

You are given a sequence $A=(A_1,A_2,\ldots,A_N)$ of length $N$ consisting of non-negative integers.

Determine if there is an even number represented as the sum of two different elements of $A$. If it exists, find the maximum such number.

Constraints

  • $2\leq N \leq 2\times 10^5$
  • $0\leq A_i\leq 10^9$
  • The elements of $A$ are distinct.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Print -1 if there is no even number represented as the sum of two different elements of $A$.

If such an even number exists, print the maximum such number.


Sample Input 1

3
2 3 4

Sample Output 1

6

The values represented as the sum of two distinct elements of $A$ are $5$, $6$, and $7$. We have an even number here, and the maximum is $6$.


Sample Input 2

2
1 0

Sample Output 2

-1

The value represented as the sum of two distinct elements of $A$ is $1$. We have no even number here, so -1 should be printed.

Input

题意翻译

# [ABC272C] Max Even ## 题目描述 [problemUrl]: https://atcoder.jp/contests/abc272/tasks/abc272_c 给定一个长度为 $N$ 的非负整数序列 $A$ 请你选出两个数,使这两个数的和为偶数,求这两个数和的最大值。如果不存在两个数和为偶数,则输出 `-1` 。 ## 输入格式 第一行:一个正整数 $N$。 第二行:$N$ 个非负整数 $a_i$。 > $ N $ $ A_1 $ $ A_2 $ $ \ldots $ $ A_N $ ## 输出格式 如果任意两数之和都不为偶数,则输出 `-1`。 存在和为偶数时,输出其最大值。 ## 样例 #1 ### 样例输入 #1 ``` 3 2 3 4 ``` ### 样例输出 #1 ``` 6 ``` ## 样例 #2 ### 样例输入 #2 ``` 2 1 0 ``` ### 样例输出 #2 ``` -1 ``` ## 提示 ### 数据范围 - $ 2\leq\ N\ \leq\ 2\times\ 10^5 $ - $ 0\leq\ A_i\leq\ 10^9 $ - $ A $ 中的元素互不相同 - $ A $ 中的元素均为整数 ### 样例 1 说明 $ A $ 中任意2个元素的和值为$ 5,6,7 $ 。其中存在偶数,其最大值为 6。 ### 样例 2 说明 $ A $ 中任意2个元素的和值为$ 1 $ 。其中不存在偶数,所以输出 `-1` 。

Output

得分:300分

问题描述

给你一个长度为 N 的序列 A = (A_1, A_2, ..., A_N),由非负整数组成。

判断是否存在一个可以用 A 中两个不同的元素相加得到的偶数。如果存在,找到最大的这样的数。

限制条件

  • $2\leq N \leq 2\times 10^5$
  • $0\leq A_i\leq 10^9$
  • A 中的元素都是不同的。
  • 输入中的所有值都是整数。

输入

输入从标准输入按以下格式给出:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

输出

如果不存在可以用 A 中两个不同的元素相加得到的偶数,打印 -1。

如果存在这样的偶数,打印最大的这样的数。


样例输入 1

3
2 3 4

样例输出 1

6

可以用 A 中两个不同的元素相加得到的值有 5、6 和 7。这里有一个偶数,最大的是 6。


样例输入 2

2
1 0

样例输出 2

-1

可以用 A 中两个不同的元素相加得到的值是 1。这里没有偶数,所以应该打印 -1。

加入题单

算法标签: