올림픽 종목 투표"
in Algorithm on SW Expert Academy
SW Expert Academy 3347: 올림픽 종목 투표
소스코드
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int tc=1; tc<=T; tc++) {
int N = sc.nextInt(); //종목개수
int M = sc.nextInt(); //위원수
int[] A = new int[N+1];
int[] B = new int[M+1];
int[] vote = new int[N+1];
for(int i=1; i<=N; i++)
A[i] = sc.nextInt();
for(int i=1; i<=M; i++)
B[i] = sc.nextInt();
for(int i=1; i<=M; i++) {
int cost = B[i];
for(int j=1; j<=N; j++) {
int fun = A[j];//개최비용
if(cost>=fun) { //개최비용이 넘지 않는다면 투표
vote[j] += 1;
break;
}
}
}
int max = 0;
int ans = 0;
for(int i=0; i<N; i++) {
if(vote[i]>max) {
max = vote[i];
ans = i;
}
}
System.out.println("#"+tc+" "+ans);
}
}
}