문제 링크 - https://www.acmicpc.net/problem/11399
🌱 문제
🌱 풀이 및 코드
- 풀이 : 인출하는데 적게 걸리는 사람이 앞에 와야 결과적으로 걸리는 시간의 합이 최소가 된다.
- 그러므로, 오름차순으로 정렬한 후, 각 사람의 걸리는 시간을 배열에 저장한 후, 그 값들을 더하면 모든사람의 총합이 된다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
int arr[1001];
int answer;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
vector<int> v(n);
for(int i=0; i<n; i++){
cin>>v[i];
}
sort(v.begin(), v.end());
arr[0]=v[0];
for(int i=1; i<n; i++){
arr[i]=arr[i-1]+v[i];
}
for(int i=0; i<n; i++){
answer+=arr[i];
}
cout<<answer<<"\n";
}