-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCF680ABearAndFiveCards.java
More file actions
58 lines (53 loc) · 1.67 KB
/
CF680ABearAndFiveCards.java
File metadata and controls
58 lines (53 loc) · 1.67 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.IntStream;
/**
* See
* <a href="http://codeforces.com/problemset/problem/680/A">Bear and Five
* Cards</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class CF680ABearAndFiveCards {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int[] a = readSortedArray();
int[] aux = new int[5];
System.arraycopy(a, 0, aux, 0, 5);
int sum = 501;
int sumaAux = 0;
for (int i = 4; i >= 2; i--) {
if (a[i] == a[i - 1] && a[i - 1] == a[i - 2]) {
a[i] = 0;
a[i - 1] = 0;
a[i - 2] = 0;
sum = IntStream.of(a).sum();
break;
}
}
for (int i = 4; i >= 1; i--) {
if (aux[i] == aux[i - 1]) {
aux[i] = 0;
aux[i - 1] = 0;
sumaAux = IntStream.of(aux).sum();;
if (sumaAux < sum) {
sum = sumaAux;
out.println(sum);
out.close();
}
break;
}
}
out.println(IntStream.of(a).sum());
out.close();
}
private static int[] readSortedArray() throws IOException {
String[] line = in.readLine().split("\\s");
int[] a = Arrays.stream(line).mapToInt(Integer::parseInt).sorted().toArray();
return a;
}
}