백준 11399번

2020. 10. 6. 23:11coding study

백준 11399번

 

* 사진 출처 : www.acmicpc.net/problem/11399

[풀이과정]

 

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(int a, char *arr[]) {
int n; int time = 0;  //현재 걸린 시간 =time
int sum = 0;
vector<int> v;


cout << "몇 명인가? :";
cin >> n;

for (int i = 0; i < n; ++i) {

 int x;

 cin >> x;

 v.push_back(x);
}

sort(v.begin(), v.end());  //시간적게 걸린 사람부터 정렬하기

for (int i = 0; i < v.size(); ++i) {
time += v[i];
sum += time; // 걸린 시간을 sum에 더하기
}

cout << sum << '\n';

system("pause");

return 0;
}

 

[결과]

사람의 수와 각 사람이 걸리는 시간을 입력받는다.

그 입력받은 수를 vector,sort를 이용해 시간이 적게 걸린 순으로 정렬한다.

그리고 걸린 시간을 time으로 받고 총 time은 sum에 저장하게 한다.

'coding study' 카테고리의 다른 글

백준 2580번  (0) 2020.10.14
백준 14888번  (0) 2020.10.14
백준 2309번  (0) 2020.10.06
백준 10814번  (0) 2020.09.23
백준 2751번  (0) 2020.09.22