Skip to content

Commit c394d38

Browse files
committed
- Add: Weekly Contest 366
1 parent eb49cd3 commit c394d38

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
fun minProcessingTime(pTimes: List<Int>, tasks: List<Int>): Int {
3+
var res = 0
4+
val pTimes = pTimes.sorted()
5+
val tasks = tasks.sortedDescending()
6+
7+
var i = 0
8+
pTimes.forEach { pTime ->
9+
var total = 0
10+
repeat(4) {
11+
total = max(total, pTime + tasks[i])
12+
i++
13+
}
14+
res = max(res, total)
15+
}
16+
return res
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
fun maxSum(nums: List<Int>, k: Int): Int {
3+
val bits = IntArray(32)
4+
val offset = 1000000007L
5+
nums.forEach { num ->
6+
repeat(32) { i ->
7+
if (num and (1 shl i) != 0) bits[i]++
8+
}
9+
} //counting for each bit
10+
11+
var res = 0L
12+
repeat(k) {
13+
var cur = 0L
14+
repeat(32) { i ->
15+
if (bits[i] > 0) {
16+
bits[i]--
17+
cur = cur or (1 shl i).toLong()
18+
}
19+
} //pick all available bits
20+
res = (res + cur * cur % offset) % offset
21+
}
22+
return res.toInt()
23+
}
24+
}

0 commit comments

Comments
 (0)