상세 컨텐츠

본문 제목

백준#1026 - 보물

C#/알고리즘

by McRobbin 2020. 4. 20. 11:15

본문

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

 

1026번: 보물

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

www.acmicpc.net

정렬로 분류된 1026 - 보물 문제 입니다.

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _1026
{
    class Program
    {
 
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            string[] AString = Console.ReadLine().Split(' ');
            string[] BString = Console.ReadLine().Split(' ');
 
            var AList = new List<int>();
            var BList = new List<int>();
 
            for(int i = 0; i < AString.Length; i++)
            {
                AList.Add(int.Parse(AString[i]));
                BList.Add(int.Parse(BString[i]));
            }
 
            AList.Sort();
            BList.Sort();
            BList.Reverse();
 
            int total = 0;
            for (int i = 0; i < AList.Count; i++)
                total += AList[i] * BList[i];
 
            Console.WriteLine(total);
        }
    }
}
 
 
 

 

배열에 순서에는 관심이 없습니다. 결국 그 총합을 구하면 되기 때문에.

첫 배열을 오름차순 정렬, 두번째 배열을 내림차순 정렬 합니다.

그 곱하기의 합을 출력합니다.

'C# > 알고리즘' 카테고리의 다른 글

백준#11650 - 좌표 정렬하기  (0) 2020.04.20
백준#1181 - 단어 정렬  (0) 2020.04.20
백준#1427 - 소트인사이드  (0) 2020.04.19
백준#1543 - 문서 검색  (0) 2020.04.18
백준#1969 - DNA  (0) 2020.04.17

관련글 더보기