LV 3: 인사고과

ewillwin·2023년 10월 3일
0

문제 링크

LV 3: 인사고과


구현 방식

  • scores를 근무태도점수에 대해 내림차순, 동료평가점수에 대해 오름차순으로 정렬
    -> 이렇게 해주면, 뒤에 나온 학생의 동료평가점수가 앞에 나온 어떤 학생의 동료평가점수(max_b)보다 크거나 같을 때에만 인센티브를 받을 수 있게 됨

코드

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(vector<int> a, vector<int> b){
    if (a[0] > b[0]){
        return true;
    }
    else if (a[0] == b[0]){
        return a[1] < b[1];
    }
    else{
        return false;
    }
}

int solution(vector<vector<int>> scores) {
    int answer = 1;
    
    int target_a = scores[0][0];
    int target_b = scores[0][1];
    int target_score = target_a + target_b;
    sort(scores.begin(), scores.end(), cmp);
    int max_b = 0;
    
    for (int i=0; i<scores.size(); i++){
        if (target_a < scores[i][0] && target_b < scores[i][1]){
            return -1;
        }
        if (max_b <= scores[i][1]){
            max_b = scores[i][1];
            if (scores[i][0] + scores[i][1] > target_score){
                answer++;
            }
        }
    }
    
    return answer;
}

def solution(scores):
    target_a, target_b = scores[0]; target_score = sum(scores[0])
    scores.sort(key=lambda x: (-x[0], x[1])) #근무태도점수에 대해 내림차순, 동료평가점수에 대해 오름차순 정렬
    max_b = 0
    
    answer = 1
    for a, b in scores:
        if target_a < a and target_b < b: return -1
        if b >= max_b:
            max_b = b
            if a + b > target_score:
                answer += 1
    return answer
profile
💼 Software Engineer @ LG Electronics | 🎓 SungKyunKwan Univ. CSE

0개의 댓글