문제 - 인사고과
완호는 scores[0]의 점수를 가지고 있다.
import java.util.*;
class Solution {
public int solution(int[][] scores) {
int answer = 1;
int wanho[] = scores[0];
//인센티브 받을 수 없는 대상 제외
ArrayList<int []> ary = new ArrayList<>();
Arrays.sort(scores, (x,y) -> {
if(x[0] == y[0])
return x[1]-y[1];
return y[0] - x[0];
} );
int maxScore = scores[0][1];
ary.add(scores[0]);
for(int i =1; i< scores.length;i++)
{
if(scores[i][1] < maxScore)
{
if(scores[i][0] == wanho[0] && scores[i][1] == wanho[1])
return -1;
}
else{
ary.add(scores[i]);
maxScore = scores[i][1];
}
}
//두 점수의 합산으로 내림차순 정렬
Collections.sort(ary,new Comparator<int []>(){
@Override
public int compare(int a[],int b[])
{
int as = a[0]+a[1];
int bs = b[0]+b[1];
return bs - as;
}
});
int sum = wanho[0] + wanho[1];
for(int i=0;i<ary.size();i++)
{
int temp = ary.get(i)[0] + ary.get(i)[1];
if(temp > sum)
answer++;
else
break;
}
return answer;
}
}