File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ import java .io .*;
3+ import java .util .*;
4+
5+ public class Main {
6+
7+ public static void main (String [] args ) throws IOException {
8+
9+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
10+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
11+
12+ int N = Integer .parseInt (br .readLine ());
13+ long M = Long .parseLong (br .readLine ());
14+
15+ int [] j = new int [N ];
16+
17+ StringTokenizer st = new StringTokenizer (br .readLine ());
18+
19+ for (int i = 0 ; i <N ; i ++){
20+ j [i ] = Integer .parseInt (st .nextToken ());
21+ }
22+
23+ Arrays .sort (j );
24+
25+ int start = 0 ;
26+ int end = N -1 ;
27+ int answer = 0 ;
28+
29+ while (start < end ){
30+
31+ if (j [start ] + j [end ] < M ){
32+ start ++;
33+ }else if (j [start ] + j [end ] == M ){
34+ answer ++;
35+ start ++;
36+ end --;
37+ }else {
38+ end --;
39+ }
40+
41+ }
42+
43+ bw .write (answer +"" );
44+ bw .flush ();
45+
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments