250x250
Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 리소스모니터링
- BFS
- set
- union_find
- CSS
- List
- Calendar
- 스택
- 큐
- math
- 스프링부트
- date
- 힙덤프
- string
- Properties
- NIO
- html
- deque
- scanner
- dfs
- alter
- spring boot
- Union-find
- JPA
- priority_queue
- sql
- Java
- map
- javascript
- GC로그수집
Archives
- Today
- Total
매일 조금씩
[C++] 프로그래머스 : 구명보트 본문
728x90
반응형
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
int answer = 0;
int boat = 0;
sort(people.begin(), people.end());
int begin = 0;
int end = people.size()-1;
while(begin <= end){
if(begin == end){
boat++;
break;
}
if(people[begin] + people[end] <= limit){
begin++;
}
end--;
boat++;
}
answer = boat;
return answer;
}
728x90
반응형
'알고리즘 > 그리디' 카테고리의 다른 글
[C++] 프로그래머스 : 단속 카메라 (0) | 2021.02.02 |
---|---|
[C++] 프로그래머스 : 섬 연결하기 (0) | 2021.02.02 |
[C++] 프로그래머스 : 큰 수 만들기 (0) | 2021.02.02 |
[C++] 프로그래머스 : 조이스틱 (0) | 2021.02.02 |
[C++] 프로그래머스 : 체육복 (0) | 2021.02.02 |