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 (
3+ process . platform === "linux"
4+ ? "/dev/stdin"
5+ : require ( "path" ) . join ( __dirname , "input.txt" ) ,
6+ "utf8"
7+ )
8+ . trim ( )
9+ . split ( "\n" ) ;
10+
11+ function solution ( input ) {
12+ const N = Number ( input [ 0 ] ) ;
13+ const circles = [ ] ;
14+
15+ for ( let i = 1 ; i <= N ; i ++ ) {
16+ const [ x , r ] = input [ i ] . split ( " " ) . map ( Number ) ;
17+ const id = i ;
18+ circles . push ( [ x - r , id , 0 ] ) ;
19+ circles . push ( [ x + r , id , 1 ] ) ;
20+ }
21+
22+ circles . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ;
23+
24+ const stack = [ ] ;
25+
26+ for ( const [ _ , id , type ] of circles ) {
27+ if ( type === 0 ) {
28+ stack . push ( [ id , type ] ) ;
29+ } else {
30+ if ( stack . length === 0 || stack [ stack . length - 1 ] [ 0 ] !== id ) {
31+ return "NO" ;
32+ }
33+ stack . pop ( ) ;
34+ }
35+ }
36+
37+ return "YES" ;
38+ }
39+
40+ console . log ( solution ( input ) ) ;
You can’t perform that action at this time.
0 commit comments