Wrong Answer
Code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int testcases = in.nextInt();
while (testcases-- > 0) {
int siz = in.nextInt();
int ops = in.nextInt();
String word = in.next();
PriorityQueue<Long> pq = new PriorityQueue<>(Comparator.reverseOrder());
int curr = 0;
for (char c : word.toCharArray()) {
if (c == '1') {
curr++;
} else {
if (curr != 0) pq.add((long) curr);
curr = 0;
}
}
if (curr != 0) pq.add((long) curr);
while (pq.size() > 1 && ops > 0) {
long first = pq.poll();
long second = pq.isEmpty() ? 0 : pq.poll();
pq.offer(first + second);
ops--;
}
System.out.println(pq.peek());
}
in.close();
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1159 Binary String
- Contest
- Brain Booster #8
- Language
- Java 8 (OpenJDK 1.8.0_422)
- Submit At
- 2025-02-17 15:04:43
- Judged At
- 2025-02-17 15:04:43
- Judged By
- Score
- 0
- Total Time
- 643ms
- Peak Memory
- 42.016 MiB