File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
AlgorithmDrills/src/Baekjoon Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ package Baekjoon ;
2+ import java .io .BufferedReader ;
3+ import java .io .IOException ;
4+ import java .io .InputStreamReader ;
5+ import java .util .Arrays ;
6+ import java .util .StringTokenizer ;
7+
8+ public class No1940 {
9+ public static void main (String [] args ) throws IOException {
10+ BufferedReader bf = new BufferedReader (new InputStreamReader (System .in ));
11+
12+ int material = Integer .parseInt (bf .readLine ()); // 재료의 수
13+ int armour = Integer .parseInt (bf .readLine ()); // 갑옷의 수
14+
15+ int [] A = new int [material ];
16+ StringTokenizer st = new StringTokenizer (bf .readLine ());
17+ for (int i = 0 ; i < material ; i ++) {
18+ A [i ] = Integer .parseInt (st .nextToken ()); // 재료배열 저장
19+ }
20+
21+ Arrays .sort (A ); // 재료배열 저장
22+ int count = 0 ; // 갑옷이 되는 경우의 수
23+ int left = 0 ;
24+ int right = material - 1 ;
25+
26+ // 투 포인터 이동규칙, material과 armour가 만날 때까지 반복
27+ while (left < right ) {
28+ if (A [left ] + A [right ] < armour ) {
29+ left ++;
30+ } else if (A [left ] + A [right ] > armour ) {
31+ right --;
32+ } else {
33+ count ++;
34+ left ++;
35+ right --;
36+ }
37+ }
38+ System .out .println (count );
39+ bf .close ();
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments