File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1+ // 월급날 하루전!
2+ const fs = require ( "fs" ) ;
3+ const filePath = process . platform === "linux" ? "/dev/stdin" : "./서정우/input.txt" ;
4+ const input = fs . readFileSync ( filePath ) . toString ( ) . trim ( ) . split ( "\n" ) ;
5+
6+ const [ N , d , k , c ] = input [ 0 ] . split ( " " ) . map ( Number ) ;
7+ const sushies = input . slice ( 1 ) . map ( Number ) ;
8+
9+ let maxKind = 0 ;
10+ const window = new Map ( ) ;
11+
12+ for ( let i = 0 ; i < k ; i ++ ) {
13+ window . set ( sushies [ i ] , ( window . get ( sushies [ i ] ) || 0 ) + 1 ) ;
14+ }
15+
16+ for ( let i = 0 ; i < N ; i ++ ) {
17+ let kind = window . size ;
18+ if ( ! window . has ( c ) ) {
19+ kind ++ ;
20+ }
21+ maxKind = Math . max ( maxKind , kind ) ;
22+
23+ const removeIdx = i ;
24+ const addIdx = ( i + k ) % N ;
25+
26+ if ( window . get ( sushies [ removeIdx ] ) === 1 ) {
27+ window . delete ( sushies [ removeIdx ] ) ;
28+ } else {
29+ window . set ( sushies [ removeIdx ] , window . get ( sushies [ removeIdx ] ) - 1 ) ;
30+ }
31+
32+ window . set ( sushies [ addIdx ] , ( window . get ( sushies [ addIdx ] ) || 0 ) + 1 ) ;
33+ }
34+
35+ console . log ( maxKind ) ;
Original file line number Diff line number Diff line change 1- 4
1+ 8 30 4 30
2+ 7
3+ 9
4+ 7
5+ 30
6+ 2
7+ 7
8+ 9
9+ 25
You can’t perform that action at this time.
0 commit comments