We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a577f83 commit 5b571f6Copy full SHA for 5b571f6
ABCクラス/AtCoder Beginner Contest 272/C - Max Even.py
@@ -1,3 +1,31 @@
1
"""
2
https://atcoder.jp/contests/abc272/tasks/abc272_c
3
-"""
+"""
4
+from typing import List
5
+
6
7
+class Solution:
8
+ @staticmethod
9
+ def max_even(a: List[int]) -> int:
10
11
+ odd = [i for i in a if i % 2 != 0]
12
+ even = [i for i in a if i % 2 == 0]
13
14
+ odd.sort()
15
+ even.sort()
16
17
+ if len(even) < 2:
18
+ if len(odd) < 2:
19
+ return -1
20
+ else:
21
+ return odd[-1] + odd[-2]
22
+ elif len(odd) < 2:
23
+ return even[-1] + even[-2]
24
25
+ return max(odd[-1] + odd[-2], even[-1] + even[-2])
26
27
28
+if __name__ == '__main__':
29
+ N = int(input())
30
+ A = [int(i) for i in input().split()]
31
+ print(Solution.max_even(A))
0 commit comments