Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 1940번 주몽 (silver 4 본문
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int m=Integer.parseInt(br.readLine());
StringTokenizer st=new StringTokenizer(br.readLine());
int[] num=new int[n];
for(int i=0; i<n; i++){
num[i]=Integer.parseInt(st.nextToken());
}
Arrays.sort(num);
int answer=0;
int start=0;
int end=n-1;
while(end!=start){
int temp=num[start]+num[end];
if(temp==m){
answer+=1;
start+=1;
}
else if(temp>m){
end-=1;
}
else{
start+=1;
}
}
System.out.print(answer);
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 1309번 동물원 (silver 1 (0) | 2023.05.28 |
---|---|
[백준] 1253번 좋다 문제 (gold 4 (0) | 2023.05.28 |
[백준] 11660번 구간 합 구하기 5 (silver 5 (0) | 2023.05.26 |
[백준] 5347번 LCM (silver 5 (0) | 2023.05.25 |
[백준] 1934번 최소공배수 (bronze 1 (0) | 2023.05.24 |