SMALL

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

 

2217번: 로프

N(1 ≤ N ≤ 100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하

www.acmicpc.net

 


  • 문제


  • 문제풀이

로프가 최대로 견딜 수 있는 무게는 배열을 정렬한 후 작은것부터 무게*N-i개 이다. 반복문을 통해 max값을 최신화해준다.


  • 코드 1
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] rope = new int[N];
        int sum = 0;
        int max = 0;
        for(int i = 0; i < N; i++)
        {
            rope[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(rope);
        for(int i = 0; i < N; i++)
        {
            sum = rope[i] * (N - i);
            if (sum > max)
            {
                max = sum;
            }
        }
        Console.WriteLine(max);
    }
}

  • 후기

규칙을 발견해서 금방 풀 수 있었다.

LIST

+ Recent posts