-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathYJ_42885.java
More file actions
33 lines (29 loc) ยท 879 Bytes
/
YJ_42885.java
File metadata and controls
33 lines (29 loc) ยท 879 Bytes
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
31
32
33
import java.util.*;
/**
* ์๊ณ ๋ฆฌ์ฆ: ํฌํฌ์ธํฐ O(NlogN)
* ์๊ฐ๋ณต์ก๋: 1 <= N <= 50,000
* ์ต์
์ ๊ฒฝ์ฐ ๋ชจ๋ ์ง์ ์ ๋ค ๊ฑฐ์น๋ฉด O(N)
* ์ ๋ ฌ ํ์ O(NlogN)
* ์์ด๋์ด:
* ๋งจ ์ ๊ฐ๋ฒผ์ด ์ฌ๋ + ๋งจ ๋ค ๋ฌด๊ฑฐ์ด ์ฌ๋์ด ๋์น ๊ฐ๋ฅํ์ง ์ฒดํฌ
*/
public class YJ_42885 {
public static void main(String[] args) {
int[] people = {70, 80, 50};
int limit = 100;
System.out.println(getBoatCount(people, limit));
}
static int getBoatCount (int[] people, int limit) {
int boat = 0;
Arrays.sort(people);
int start = 0;
for(int end=people.length-1; start<=end; end--){
//๊ธฐ์ค๊ฐ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๊ฒฝ์ฐ
if(people[start] + people[end] <= limit){
start++;
}
boat++;
}
return boat;
}
}