Algorithm
[Algo] 프로그래머스 인사고과
조핑구
2024. 5. 9. 10:30
import java.util.*;
class Solution {
static class Node {
int a;
int b;
int sum;
Node(int a, int b){
this.a=a;
this.b=b;
sum=a+b;
}
}
public int solution(int[][] scores) {
int answer = -1;
int len=scores.length;
List<Node>list=new ArrayList<>();
int wanho=scores[0][0]+scores[0][1];
for(int i=1; i<len; i++){
int s=scores[i][0] + scores[i][1];
if(s >wanho){
list.add(new Node(scores[i][0], scores[i][1]));
}
}
Collections.sort(list, new Comparator<Node>(){
@Override
public int compare(Node o1, Node o2){
return o1.sum-o2.sum;
}
});
int cnt=1;
for(int i=0; i<list.size(); i++){
if(scores[0][0]<list.get(i).a && scores[0][1]<list.get(i).b){
return -1;
}
boolean flag=true;
for(int j=0; j<list.size(); j++){
if(list.get(i).a<list.get(j).a && list.get(i).b<list.get(j).b){
flag=false;
break;
}
}
if(flag) cnt++;
}
return cnt;
}
}
두 점수의 합이 높은 순으로 석차를 내고 합이 동일하면 동석차로 본다. 따라서 완호의 석차는 완호보다 합이 더 많은 사람의 수이다. 하지만 합이 높아도 인센티브를 받지 못하는 경우가 있기 때문에,
- 완호보다 합이 높은 경우
- 인센티브를 받을 수 있는 경우 의 교집합의 개수를 모두 세주면 된다.