https://programmers.co.kr/learn/courses/30/lessons/12941
코딩테스트 연습 - 최솟값 만들기
길이가 같은 배열 A, B 두개가 있습니다. 각 배열은 자연수로 이루어져 있습니다. 배열 A, B에서 각각 한 개의 숫자를 뽑아 두 수를 곱합니다. 이러한 과정을 배열의 길이만큼 반복하며, 두 수를 곱
programmers.co.kr
나의 풀이
#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;
}'전공공부 > 코딩테스트' 카테고리의 다른 글
| (c++) 프로그래머스 "행렬의 곱셈" (0) | 2022.04.21 |
|---|---|
| (c++) 프로그래머스 "파보나치 수" (0) | 2022.04.20 |
| (c++) 프로그래머스 "최댓값과 최솟값" (0) | 2022.04.18 |
| (c++) 프로그래머스 "쿼드압축 후 개수 세기" (0) | 2022.04.17 |
| (c++) 프로그래머스 "땅따먹기" (0) | 2022.04.16 |