-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlowers (Contest).java
More file actions
64 lines (60 loc) · 1.48 KB
/
Flowers (Contest).java
File metadata and controls
64 lines (60 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sum=0;
int min=Integer.MAX_VALUE;
for(int i=0;i<n;i++)
{
int x=sc.nextInt();
if(x%2==0){
sum+=x-1;
x-=1;
}
else{
sum+=x;
}
if(x<min)
min=x;
}
if(sum%2==0)
sum=sum-min;
System.out.println(sum);
//second method
// Scanner sc = new Scanner(System.in);
// int n = sc.nextInt();
// int arr[] = new int[n];
// for (int i=0; i<n; i++) {
// arr[i] = sc.nextInt();
// }
// long sum = 0;
// int min = Integer.MAX_VALUE;
// for (int i=0; i<n; i++) {
// if (arr[i] % 2 == 1) {
// sum += arr[i];
// }
// else {
// sum += arr[i]-1;
// }
// if (arr[i] < min) {
// min = arr[i];
// }
// }
// if (n % 2 == 1) {
// System.out.print(sum);
// }
// else {
// if (min % 2 == 1) {
// System.out.print(sum - min);
// }
// else {
// System.out.print(sum - min + 1);
// }
// }
}
}