안선생의 개발 블로그

C++ 1026 보물 본문

백준

C++ 1026 보물

안선생 2023. 2. 11. 19:46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
void push(vector<int>& a)
{
    for (int i = 0; i < a.size(); i++)
    {
        cin >> a[i];
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
 
    int n; cin >> n;
 
    vector<int> a(n), b(n);
 
    push(a);
    push(b);
 
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<int>());
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i] * b[i];
    }
    cout << sum;
 
 
    return 0;
}
 
 
cs

 

https://www.acmicpc.net/problem/1026

 

1026번: 보물

첫째 줄에 N이 주어진다. 둘째 줄에는 A에 있는 N개의 수가 순서대로 주어지고, 셋째 줄에는 B에 있는 수가 순서대로 주어진다. N은 50보다 작거나 같은 자연수이고, A와 B의 각 원소는 100보다 작거

www.acmicpc.net

 

'백준' 카테고리의 다른 글

C++ 2164 카드2  (0) 2023.02.11
C++ 백준 2846 5와 6의 차이  (0) 2023.02.11
C++ 1789 수들의 합  (0) 2023.02.11
C++ 4796 캠핑  (0) 2023.02.11
C++ 10610 30  (0) 2023.02.11