SMALL

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

 

11399번: ATM

첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)

www.acmicpc.net


  • 문제


  • 문제풀이

입력받은 시간값을 정렬하고 시간값을 누적하여 합한 후 출력한다.

 


  • 코드 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int sum = 0;
            string[] input=Console.ReadLine().Split();
            
            int[] arr=new int[N];
            for(int i=0; i < N; i++)
            {
                int time=int.Parse(input[i]);
                arr[i]=time;
            }
            Array.Sort(arr);
            for(int j=1; j < N; j++)
            {
                arr[j]=arr[j-1]+arr[j];
                sum+=arr[j];
            }
            Console.WriteLine(sum+arr[0]);
        }
    }
}

 


  • 후기

그리디 알고리즘을 활용해 컴퓨터에게 노가다를 시킨다.

LIST

+ Recent posts