본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 1940 주몽

by 왹져박사 2023. 8. 28.

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

 

1940번: 주몽

첫째 줄에는 재료의 개수 N(1 ≤ N ≤ 15,000)이 주어진다. 그리고 두 번째 줄에는 갑옷을 만드는데 필요한 수 M(1 ≤ M ≤ 10,000,000) 주어진다. 그리고 마지막으로 셋째 줄에는 N개의 재료들이 가진 고

www.acmicpc.net

using System;

namespace _1940
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            int n = int.Parse(sr.ReadLine());
            int m = int.Parse(sr.ReadLine());
            int[] armours = new int[n];
            int count = 0;

            string[] str = sr.ReadLine().Split(' ');

            for(int i = 0; i < n; i++)
            {
                armours[i] = int.Parse(str[i]);
            }

            //이미 사용한 번호 리스트
            int[] used = new int[n];

            for(int i = 0; i < n - 1; i++)
            {
                //사용했으면 다음으로
                if (used[i] == 1) continue;
                for (int j = i + 1; j < n; j++)
                {
                    if (used[j] == 1) continue;
                    if (armours[i] + armours[j] == m)
                    {
                        count++;
                        used[i] = 1;
                        used[j] = 1;
                    }
                }
            }
            sw.WriteLine(count);

            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

 

 

드디어 실버 달았다! 야호 ^오^ !!

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 10989 수 정렬하기 3  (0) 2023.08.30
[ BOJ/C# ] 21921 블로그  (0) 2023.08.29
[ BOJ/C# ] 1159 농구 경기  (0) 2023.08.27
[ BOJ/C# ] 1764 듣보잡  (0) 2023.08.26
[ BOJ/C# ] 2839 설탕 배달  (0) 2023.08.26