File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ // https://www.acmicpc.net/problem/33524
2+
3+ const fs = require ( "fs" ) ;
4+ const filePath = process . platform === "linux" ? "/dev/stdin" : "../input.txt" ;
5+ const input = fs . readFileSync ( filePath ) . toString ( ) . trim ( ) . split ( "\n" ) ;
6+
7+ const [ N , M ] = input [ 0 ] . split ( " " ) . map ( Number ) ;
8+ const problems = input [ 1 ] . split ( " " ) . map ( Number ) ;
9+ const users = input [ 2 ] . split ( " " ) . map ( Number ) ;
10+
11+ const sizes = [ 0 ] ;
12+ for ( let i = 1 ; ; i ++ ) {
13+ const size = 3 * i * ( i - 1 ) + 1 ;
14+ if ( size > N ) break ;
15+ sizes . push ( size ) ;
16+ }
17+
18+ problems . sort ( ( a , b ) => a - b ) ;
19+
20+ const upperBound = ( arr , target ) => {
21+ let l = 0 ;
22+ let r = arr . length ;
23+ while ( l < r ) {
24+ const mid = ( l + r ) >> 1 ;
25+ if ( arr [ mid ] <= target ) l = mid + 1 ;
26+ else r = mid ;
27+ }
28+ return l ;
29+ } ;
30+
31+ const result = users . map ( ( userSkill ) => {
32+ const count = upperBound ( problems , userSkill ) ;
33+ if ( count === 0 ) return 0 ;
34+
35+ let left = 0 ;
36+ let right = sizes . length - 1 ;
37+ let max = 0 ;
38+
39+ while ( left <= right ) {
40+ const mid = ( left + right ) >> 1 ;
41+ if ( sizes [ mid ] <= count ) {
42+ max = mid ;
43+ left = mid + 1 ;
44+ } else {
45+ right = mid - 1 ;
46+ }
47+ }
48+ return max ;
49+ } ) ;
50+
51+ console . log ( result . join ( " " ) ) ;
You can’t perform that action at this time.
0 commit comments