Recent Posts
Notice
No Rules Rules
보물 (feat. 백준, 1026번) 본문
728x90
반응형
보물
https://www.acmicpc.net/problem/1026
1026번: 보물
첫째 줄에 N이 주어진다. 둘째 줄에는 A에 있는 N개의 수가 순서대로 주어지고, 셋째 줄에는 B에 있는 수가 순서대로 주어진다. N은 50보다 작거나 같은 자연수이고, A와 B의 각 원소는 100보다 작거
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
ios::sync_with_stdio(false), cin.tie(NULL);
register int N, ans = 0;
priority_queue<int> A;
priority_queue<int, vector<int>, greater<int>> B;
cin >> N;
for(register int n = 0, v; n < N; ++n)
cin >> v, A.push(v);
for(register int n = 0, v; n < N; ++n)
cin >> v, B.push(v);
for(register int n = 0; n < N; ++n)
ans += A.top() * B.top(), A.pop(), B.pop();
cout << ans;
return 0;
}
// *&)*@*
입력으로 주어진 A는 내림차순(또는 오름차순) B는 오름차순(또는 내림차순) 으로 정렬하여 서로간 연산했을 경우, 최소값의 결과를 얻을 수 있습니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
요세푸스 문제 (feat. 백준, 1158번) (0) | 2022.09.15 |
---|---|
중복 빼고 정렬하기 (feat. 백준, 10867번) (0) | 2022.09.15 |
새로운 게임 (feat. 백준, 17780번) (0) | 2022.09.15 |
색종이 붙이기 (feat. 백준, 17136번) (0) | 2022.09.15 |
캐슬 디펜스 (feat. 백준, 17135번) (0) | 2022.09.14 |
Comments