Skip to content

Commit c3ccb00

Browse files
committed
[Silver IV] Title: 주몽, Time: 168 ms, Memory: 16432 KB -BaekjoonHub
1 parent 18611f0 commit c3ccb00

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

백준/Silver/1940. 주몽/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 2020 KB, 시간: 4 ms
7+
메모리: 16432 KB, 시간: 168 ms
88

99
### 분류
1010

1111
정렬, 두 포인터
1212

1313
### 제출 일자
1414

15-
2024년 5월 11일 20:39:15
15+
2025년 9월 17일 22:38:40
1616

1717
### 문제 설명
1818

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws IOException{
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
8+
int N = Integer.parseInt(br.readLine());
9+
int M = Integer.parseInt(br.readLine());
10+
int[] A = new int[N];
11+
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
14+
for(int i=0; i<N; i++){
15+
A[i] = Integer.parseInt(st.nextToken());
16+
}
17+
18+
Arrays.sort(A);
19+
20+
int start = 0;
21+
int end = N-1;
22+
int count = 0;
23+
24+
while(start < end){
25+
if(A[start] + A[end] < M) {
26+
start++;
27+
}
28+
else if(A[start] + A[end] > M){
29+
end--;
30+
}
31+
else {
32+
count++;
33+
start++;
34+
end--;
35+
}
36+
}
37+
38+
System.out.println(count);
39+
}
40+
}

0 commit comments

Comments
 (0)