MAXES - Editorial

PROBLEM LINK:

Practice
Contest

Author: Riddhish Lichade
Tester: Riddhish Lichade
Editorialist: Riddhish Lichade

DIFFICULTY:

SIMPLE

PREREQUISITES:

Conditional Statements

PROBLEM:

Meena is given a list AA of NN integers. He can use any of these integers at max one time. His task is to get the maximum possible even sum. Help Meena to find this sum.

Note: Any number that can be divided by two to create another whole number is even.

EXPLANATION:

We are given an array of N integers. Our task is to find the maximum sum using the elements of the array which is even. All the elements are positive numbers. Find the minimum odd number (say x) in the array. If the sum of all the elements in the array is odd, then subtract x from it otherwise, print the sum as it is.

SOLUTIONS:

Setter's Solution
from sys import stdin
for _ in range(int(stdin.readline())):
    n=int(input())
    l = list(map(int, stdin.readline().strip().split()))
    s=0
    m=float('inf')
    for i in l:
        s+=i
        if(i&1):
            m=min(m,i)
    if(s&1):
        s-=m
    print(s)