패스트터틀

(Baekjoon) GreedyAlgorithm - (5) 로프 본문

Algorithm/baekjoon

(Baekjoon) GreedyAlgorithm - (5) 로프

SudekY 2019. 11. 6. 17:53

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

 

2217번: 로프

N(1≤N≤100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하지만 여러 개의 로프를 병렬로 연결하면 각각의 로프에 걸리는 중량을 나눌 수 있다. k개의 로프를 사용하여 중량이 w인 물체를 들어올릴 때, 각각의 로프에는 모두 고르게 w/k 만큼의 중량이 걸리게 된다. 각 로프들에 대한 정보가 주어졌을 때, 이 로프들을

www.acmicpc.net

package GreedyAlgorithm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

/*
2
10
15
1500
2000
3000
4000
5000

가장큰것은 혼자 들면 5000
그보다 낮은것을 합해서 들면 4000 * 2
그보다 낮은것을 더해서 들면 3000 * 3 
...

*/

public class _2217{
    public static void main(String[] args) {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int count = Integer.parseInt(br.readLine());
            List<Integer> list = new ArrayList<Integer>();
            List<Integer> sum = new ArrayList<Integer>();
            for (int i = 0; i < count; i++) {
                list.add(i,Integer.parseInt(br.readLine()));
            }

            Collections.sort(list,Collections.reverseOrder());


            for (int i = 0; i < list.size() ;  i++) {
                sum.add(i,list.get(i) * (i+1) );
            }

            Collections.sort(sum);

            System.out.println(sum.get(sum.size() - 1));
            

        } catch (IOException e){
            e.printStackTrace();
        }


    }

}

 

참고로 문제 이해하는데 걸린시간이 푸는시간보다 더 많다.

주석 참고하기

 

 

백준문제풀이Github : 

https://github.com/sdk0213/baekjoon-study

 

sdk0213/baekjoon-study

solve a baekjoon question. Contribute to sdk0213/baekjoon-study development by creating an account on GitHub.

github.com

 

Comments