uploaded at 2022. 12. 21. 오전 1:00:29
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/42885#
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
class Solution {
|
||||||
|
public int solution(int[] people, int limit) {
|
||||||
|
int answer = 0, ll = 0;
|
||||||
|
Arrays.sort(people);
|
||||||
|
for(int p = 0; p < people.length; p++){
|
||||||
|
if(people[p] > limit - people[0]) {
|
||||||
|
ll = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int p = ll; p < people.length; p++){
|
||||||
|
if(people[p] > limit - people[0]) answer ++;
|
||||||
|
}
|
||||||
|
System.out.println(ll);
|
||||||
|
if(ll!=0){
|
||||||
|
int x = 0;
|
||||||
|
for(int p = ll-1; p >= 0; p --){
|
||||||
|
if(x == p) {
|
||||||
|
answer++;
|
||||||
|
x++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(p < x) break;
|
||||||
|
if(people[x]+people[p] <= limit) {
|
||||||
|
answer ++;
|
||||||
|
x++;
|
||||||
|
} else answer++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user