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+
6+ function solution ( input ) {
7+ const n = input ;
8+ const dp = Array ( n + 1 ) . fill ( 0 ) ;
9+
10+ dp [ 1 ] = 1 ;
11+ dp [ 2 ] = 3 ;
12+
13+ for ( let i = 3 ; i <= n ; i ++ ) {
14+ dp [ i ] = ( dp [ i - 1 ] + 2 * dp [ i - 2 ] ) % 10007 ;
15+ }
16+
17+ return dp [ n ] ;
18+ }
19+
20+ console . log ( solution ( input ) ) ;
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 N = input [ 0 ] [ 0 ] ;
10+ const an = input [ 1 ] ;
11+
12+ let current = an [ 0 ] ;
13+ let maxProfit = 0 ;
14+
15+ for ( const a of an ) {
16+ maxProfit = Math . max ( maxProfit , a - current ) ;
17+
18+ current = Math . min ( current , a ) ;
19+ }
20+
21+ return maxProfit ;
22+ }
23+
24+ console . log ( solution ( input ) ) ;
You can’t perform that action at this time.
0 commit comments