[Programmers] 구명보트

Time Lapse :33min 55sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <vector>
#include <algorithm>
using namespace std;

int solution(vector<int> people, int limit) {
register int answer = 1;
sort(people.begin(),people.end());
register vector<int>::iterator back_it = people.end()-1, front_it = people.begin();
while(front_it!=back_it){
if(*back_it-- + *front_it<=limit){
if(back_it==front_it)
return answer;
++front_it;
}
++answer;
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/safeboat/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.