@@ -29,19 +29,27 @@ class Contest {
29
29
this . luck = luck ;
30
30
this . important = important ;
31
31
}
32
+
33
+ getLuck ( ) {
34
+ return this . luck ;
35
+ }
36
+
37
+ isImportant ( ) {
38
+ return this . important !== 0 ;
39
+ }
32
40
}
33
41
34
42
export function luckBalance ( k , contests ) {
35
- // Write your code here
36
43
let importantContests = [ ] ;
37
44
const nonimportantContests = [ ] ;
38
45
39
- contests . forEach ( ( contest ) => {
40
- const [ luck , important ] = [ ...contest ] ;
41
- if ( important === 1 ) {
42
- importantContests . push ( new Contest ( luck , important ) ) ;
46
+ contests . forEach ( ( contestData ) => {
47
+ const [ luck , important ] = [ ...contestData ] ;
48
+ const contest = new Contest ( luck , important ) ;
49
+ if ( contest . isImportant ( ) ) {
50
+ importantContests . push ( contest ) ;
43
51
} else {
44
- nonimportantContests . push ( new Contest ( luck , important ) ) ;
52
+ nonimportantContests . push ( contest ) ;
45
53
}
46
54
} ) ;
47
55
@@ -55,11 +63,11 @@ export function luckBalance(k, contests) {
55
63
const cut = Math . min ( k , size ) ;
56
64
57
65
for ( let i = 0 ; i < cut ; i ++ ) {
58
- total += importantContests [ i ] . luck ;
66
+ total += importantContests [ i ] . getLuck ( ) ;
59
67
}
60
68
61
69
for ( let i = cut ; i < size ; i ++ ) {
62
- total -= importantContests [ i ] . luck ;
70
+ total -= importantContests [ i ] . getLuck ( ) ;
63
71
}
64
72
65
73
nonimportantContests . forEach ( ( contest ) => {
0 commit comments