코딩 공부 연습

프로그래머스 - 최솟값 만들기

miffy짱 2022. 9. 17. 19:07
반응형

가장 작은수랑 가장 큰수를 짝지어서 곱해주면 된다. 쉽다!!!

 

#include <iostream>
#include<vector>
#include <algorithm>

using namespace std;

int solution(vector<int> A, vector<int> B)
{
    int answer = 0;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end(), greater());
    for(int i = 0; i< A.size(); i++)
        answer += A[i]*B[i];
    return answer;
}

16242등