하루 한 접시

[백준] 11399번: ATM [C#]

NaZZU 2024. 3. 21. 00:30

첫째 줄에 몇명이 돈을 인출하러 왔는지, 둘째 줄에 돈을 인출하는데 각각 몇분 씩 걸리는지가 한 줄로 입력된다.

각종 기호를 통해 착각이 들 수 있겠으나, 우리에게 중요한 건 오직 모두가 인출한는데 걸리는 '최단 시간' 이므로 int형 배열에 시간만 넣은 후 오름차순 정렬하여 총 인출 시간을 구하면 된다

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
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
 
namespace 연습장
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using var reader = new StreamReader(Console.OpenStandardInput()) ;
            using var print = new StreamWriter(Console.OpenStandardOutput());
            int N = int.Parse(reader.ReadLine());
            int tot = 0int cnt = 0;
 
            string[] str = reader.ReadLine().Split();
            int[] num = new int[N];
 
            for(int i=0; i<N; i++)
            {
                num[i] = int.Parse(str[i]);
            }
            Array.Sort(num);
 
            for(int j = 0; j < N; j++)
            {
                for(int k = 0; k <= cnt; k++ )
                {
                    tot += num[k];
                } cnt++;
            }
            print.WriteLine(tot);            
 
        }
    }
}
cs

이렇게나 간단한 문제인데, 인덱스 번호도 고려할라고 이차원 배열이니 튜플 리스트니 끙끙대다가 시간만 신경쓰면 된다는걸 깨닫고는 너무 허무했다. 다음부터는 문제를 꼼꼼히 읽어, 문제가 요구하는 사항에 맞춰 코딩을 해야겠다.

그리고 그리디 알고리즘 관련 문제라는데... 아직 배우지 못한 부분이라 얼렁뚱땅 넘어간거 같아서 좀 그렇다...