[CodeForces] [621A] Wet Shark and Odd and Even

Problem Description

Loading...

Problem Analysis

Find the maximum value such that the sum of the array’s numbers is odd

You only need to check whether the final sum is odd
If it is odd, just subtract the smallest odd number

Otherwise output it directly

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>
int a[100200];
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		for(int i=0; i<n; i++)
			scanf("%d",&a[i]);
		__int64 sum=0,min=9999999999;
		for(int i=0; i<n; i++) {
			if(a[i]&1&&a[i]<min)
				min=a[i];
			sum+=(__int64)a[i];
		}
		printf("%I64d\n",sum&1?sum-min:sum);
	}
	return 0;
}

Problem address:【CodeForces】[621A]Wet Shark and Odd and Even

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...