https://school.programmers.co.kr/learn/courses/30/lessons/152995
근태점수, 동료 평가 점수
첫 기준 각 두 점수가 임의의 임원의 사원보다 모두 낮은 경우가 한번이라도 있으면 인센티브를 받지 못함.
두 점수의 합이 높은 순으로 석차를 내서 석차에 따라 차등 지금
완호의 석차를 알아내는게 정답
두 점수가 모두 낮다. -> 한번이라도 -> 인센못받음.
10만 * 10만 -> O(n^2) 을가면터지는걸로알고있음. -> 이중반복문은 지양한다.
1시간 정도 고민했지만 풀지 못해서 블로그를 참고했습니다.
참고 블로그 : https://chamggae.tistory.com/191
정렬을 진행해야한다.
근무 태도 기준으로 내림차순으로 진행하고 만약 근무 태도가 같은 경우 팀내 평가 기준으로 오름차순을 진행합니다.
계산을 전부 했을 경우 -> 그다음 과정으로 두 값의 합을 기준으로 내림차순 정렬을 해줍니다.
코드를 참고하면서도 다른 사원은 동석차가 존재하는데 완호는 동석차가 존재하지않는 건가라는 의문이 들었는데 그 문제에 대해서는 설명이 없던게 아쉽습니다.
구현
import java.util.*;
class Solution {
public int solution(int[][] scores) {
Score wanho = new Score(scores[0][0],scores[0][1],scores[0][0]+scores[0][1]);
Arrays.sort(scores, (o1, o2) -> {
//팀내 평가 오름차순
if(o1[0] == o2[0]){
return o1[1] - o2[1];
}
//근태기준내림차순
return o2[0] - o1[0];
});
int maxpeer = scores[0][1];
//인센을 못받는 사람들 먼저 체크
for(int idx = 1;idx<scores.length;idx++){
//최대 값보다 작은 경우
if(scores[idx][1] < maxpeer){
//그게 완호인 경우 -1리턴
if(scores[idx][0] == wanho.attitude && scores[idx][1] == wanho.peer){
return -1;
}
scores[idx][0] =-1;
scores[idx][1] =-1;
//최대값 갱신
}else{
maxpeer = scores[idx][1];
}
}
//합 기준 내림차순 정렬 진행
Arrays.sort(scores,(o1,o2)-> (o2[0]+o2[1]) - (o1[0]+o1[1]));
int answer = 1;
for(int idx =0;idx<scores.length;idx++){
if(scores[idx][0] +scores[idx][1] > wanho.sum){
answer++;
}else {
break;
}
}
return answer;
}
class Score{
int attitude;
int peer;
int sum;
public Score(int attitude,int peer,int sum){
this.attitude =attitude;
this.peer = peer;
this.sum = sum;
}
}
}