/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 98ms 15.234 MiB
#2 Wrong Answer 588ms 42.016 MiB
#3 Wrong Answer 643ms 41.84 MiB

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