//https://www.acmicpc.net/problem/1026 #include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
bool cmp(int a, int b){ | |
return a>b; | |
} | |
int main(){ | |
int n; | |
cin>> n; | |
vector<int> A; | |
vector<int> B; | |
for(int i=0; i<n; i++) { | |
int a; | |
cin >> a; | |
A.push_back(a); | |
} | |
for(int i=0; i<n; i++) { | |
int b; | |
cin >> b; | |
B.push_back(b); | |
} | |
sort(B.begin(), B.end()); | |
sort(A.begin(), A.end(), cmp); | |
int ans=0; | |
for(int i=0; i<n; i++){ | |
ans+=A[i]*B[i]; | |
} | |
cout << ans; | |
return 0; | |
} |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
180423_10989_수 정렬하기 3 (0) | 2018.04.23 |
---|---|
180423_1427_소트인사이드 (0) | 2018.04.23 |
180423_2747_피보나치 수 (0) | 2018.04.23 |
180418_15683_감시 (0) | 2018.04.18 |
180417_15685_드래곤커브 (0) | 2018.04.17 |
//https://www.acmicpc.net/problem/1026 #include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
bool cmp(int a, int b){ | |
return a>b; | |
} | |
int main(){ | |
int n; | |
cin>> n; | |
vector<int> A; | |
vector<int> B; | |
for(int i=0; i<n; i++) { | |
int a; | |
cin >> a; | |
A.push_back(a); | |
} | |
for(int i=0; i<n; i++) { | |
int b; | |
cin >> b; | |
B.push_back(b); | |
} | |
sort(B.begin(), B.end()); | |
sort(A.begin(), A.end(), cmp); | |
int ans=0; | |
for(int i=0; i<n; i++){ | |
ans+=A[i]*B[i]; | |
} | |
cout << ans; | |
return 0; | |
} |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
180423_10989_수 정렬하기 3 (0) | 2018.04.23 |
---|---|
180423_1427_소트인사이드 (0) | 2018.04.23 |
180423_2747_피보나치 수 (0) | 2018.04.23 |
180418_15683_감시 (0) | 2018.04.18 |
180417_15685_드래곤커브 (0) | 2018.04.17 |