-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP503.java
More file actions
42 lines (36 loc) · 1.21 KB
/
P503.java
File metadata and controls
42 lines (36 loc) · 1.21 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
package p500_599;
//Accepted
import java.util.ArrayList;
import java.util.Scanner;
public class P503 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int d1 = sc.nextInt();
int d2 = sc.nextInt();
int[] valores = new int[d1+d2+1];
for (int j = 1; j <= d1; j++) {
for (int k = 1; k <= d2; k++) {
valores[j+k]++;
}
}
int frecuenciaMax = Integer.MIN_VALUE;
ArrayList<Integer> ganadores = new ArrayList<>();
for (int j = 2; j < valores.length; j++) {
if (valores[j]>frecuenciaMax){
ganadores.clear();
frecuenciaMax=valores[j];
ganadores.add(j);
}
else if (valores[j] == frecuenciaMax){
ganadores.add(j);
}
}
for (int j = 0; j < ganadores.size(); j++) {
System.out.print(ganadores.get(j) + (j == ganadores.size()-1 ? "":" "));
}
System.out.println();
}
}
}