Notice
Recent Posts
Recent Comments
-
[그리디] 백준 문제풀기 - 11399번 ATM 본문
https://www.acmicpc.net/problem/11399
사람의 순서에 따라 대기하는 시간을 최소로 하는 사람순서배치에 대한 문제였다. 가장 짧게 걸리는 사람부터 세우는게 전체 사람들의 소요 시간을 최소화 하는 방법이라는 그리디 알고리즘으로 풀 수 있다.
#include
#include
#include
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector times;
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
int element;
cin >> element;
times.push_back(element);
}
sort(times.begin(), times.end()); // vector, deque만 있음. queue는 없음 (begin, end)
int sum = 0;
for (int i = 1; i <= N; i++){
for (int j = 0; j < i; j++){
sum += times[j];
}
}
cout << sum << '\n';
return 0;
}
'6. Greedy' 카테고리의 다른 글
[그리디] 백준 문제풀기 - 잃어버린 괄호 (1541번) (0) | 2019.12.24 |
---|---|
[그리디] 백준 문제풀이 - 동전 0 (0) | 2019.12.23 |
Comments