백준 11399 - ATM

최대 1 분 소요

문제

백준 11399 - ATM 풀러가기

문제 분석

이 문제는 시간이 적게 걸리는 게 앞에 있을 수록, 시간의 합이 최소가 된다. 따라서 오름차순으로 정렬해서 문제를 풀면 된다.

문제 풀이(C++)

  1. 전체 코드

    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
    #include <cstdio>
    #include <algorithm>
    #include <vector>
     
    using namespace std;
     
    vector<int> p;
     
    int main() {
        int n;
     
        scanf("%d"&n);
     
        for (int i = 0; i < n; i++) {
            int temp;
            scanf("%d"&temp);
     
            p.push_back(temp);
        }
     
        sort(p.begin(), p.end());
     
        int count = 0;
     
        for (int i = 0; i < n; i++) {
            count += (p[i] * (n - i));
        }
     
        printf("%d", count);
     
        return 0;
    }
    cs






아직 배움의 과정에 있는 학생이니 내용에 부족한 점이 보이면 지적은 하되, 비난은 하지 말아주세요!!

댓글남기기