반응형
문제
https://www.acmicpc.net/problem/11399
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
해설
정렬 후 최소단위 작업부터 시작하여 누적 합계를 구하면 된다. OS에서 SJF(Shortest Job First Scheduling)라는 프로세스 스케줄링 기법과 동일한 방법이다.
#include<iostream>
#include<algorithm>
using namespace std;
void atm(){
int n;
int temp = 0;
int res = 0;
cin >> n;
int* times = new int[n];
for (int i = 0; i < n; i++) { cin >> times[i]; }
sort(times, times + n);
for (int i = 0; i < n; i++) {
temp += times[i];
res += temp;
}
cout << res;
}
int main(){
atm();
return 0;
}
반응형