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+ const input = require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( )
5+ . split ( '\n' )
6+ . map ( ( el ) => el . split ( ' ' ) . map ( Number ) ) ;
7+
8+ function solution ( input ) {
9+ const T = input [ 0 ] ;
10+ let idx = 1 ;
11+ let result = [ ] ;
12+ for ( let i = 0 ; i < T ; i ++ ) {
13+ const [ N , M ] = input [ idx ] ;
14+ const A = input [ idx + 1 ] ;
15+ const B = input [ idx + 2 ] ;
16+ A . sort ( ( a , b ) => a - b ) ;
17+ B . sort ( ( a , b ) => a - b ) ;
18+ let count = 0 ;
19+ const bMaxNum = Math . max ( ...B ) ;
20+
21+ for ( let j = 0 ; j < N ; j ++ ) {
22+ if ( A [ j ] > bMaxNum ) {
23+ count += M ;
24+ continue ;
25+ }
26+ for ( let k = 0 ; k < M ; k ++ ) {
27+ if ( A [ j ] > B [ k ] ) count ++ ;
28+ else break ;
29+ }
30+ }
31+ result . push ( count ) ;
32+
33+ idx += 3 ;
34+ }
35+ return result . join ( '\n' ) ;
36+ }
37+
38+ console . log ( solution ( input ) ) ;
39+
40+ // 노가다로 풀었더니 이진탐색이랑 4배 차이 ㄷㄷ
41+ // 배열에서 원하값 찾을 때 이진탐색 생각하기
You can’t perform that action at this time.
0 commit comments