Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d2ffadf

Browse files
1
1 parent aa42280 commit d2ffadf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎src/main/kotlin/p25xx/Problem2554.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package p25xx
2+
3+
import util.expect
4+
5+
fun main() {
6+
class Solution {
7+
fun maxCount(banned: IntArray, n: Int, maxSum: Int): Int {
8+
banned.sort()
9+
var banIndex = 0
10+
11+
var sum = 0L
12+
var result = 0
13+
for (num in 1..n) {
14+
when {
15+
sum + num > maxSum -> {
16+
break
17+
}
18+
19+
banIndex == banned.size || num < banned[banIndex] -> {
20+
sum += num
21+
result++
22+
}
23+
24+
else -> {
25+
while (banIndex < banned.size && num == banned[banIndex]) {
26+
banIndex++
27+
}
28+
}
29+
}
30+
}
31+
32+
return result
33+
}
34+
}
35+
36+
expect {
37+
Solution().maxCount(
38+
intArrayOf(1, 3, 2, 4, 5), 1, 1
39+
)
40+
}
41+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /