algorithm/BOJ

BOJ 11399번 ATM

_JunHo 2020. 1. 17. 18:57

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

github : https://github.com/junho0956/Algorithm/blob/master/11399/11399/%EC%86%8C%EC%8A%A4.cpp

 

현재 사람이 앞사람이 돈을 인출하는데 걸리는시간을 최소화하기 위해서는 앞사람이 인출하는 시간을 줄이면 된다.

==> ATM 인출 시간을 가장 작게 줄이는 방법은 정렬을 해주는 것으로 해결할 수 있다.

 

더보기
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
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int N, a;
vector<int> v;
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    int total = 0;
    for (int i = 0; i < v.size(); i++) {
        for (int k = 0; k <= i; k++) {
            total += v[k];
        }
    }
 
    cout << total;
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter