Competitive Programming Solutions

GitHub
back to dashboard

C. Finding Minimums

Codeforces - Contest #2 · limit: 1s · memory: 256MB · view on codeforces

input

8 3
4 -1 2 3 5 0 2 7

output

-1 0 2
Main.java
static void solve() {

        // Write your solution here
        int n = in.nextInt();
        int k = in.nextInt();
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < n; i++){
            int num = in.nextInt();
            min = Math.min(min, num);

            if ((i + 1) % k == 0) {
                out.print(min + " ");
                min = Integer.MAX_VALUE;
            }
        }
        
        if (n % k != 0) {
            out.print(min);
        }
    }