Submission

Status:
------TT

Score: 0

User: Jokul

Problemset: แซงรอบ

Language: c

Time: 1.092 second

Submitted On: 2025-03-24 08:03:23

#include <stdio.h>

int count_non_knocked_out_competitors(int N, int K, int lap_times[]) {
    // Find the fastest lap time
    int fastest_time = lap_times[0];
    for (int i = 1; i < N; i++) {
        if (lap_times[i] < fastest_time) {
            fastest_time = lap_times[i];
        }
    }

    // Initialize an array to track if a competitor is knocked out
    int knocked_out[N];
    for (int i = 0; i < N; i++) {
        knocked_out[i] = 0; // 0 means not knocked out
    }

    // Iterate through each lap
    for (int lap = 1; lap <= K; lap++) {
        for (int i = 0; i < N; i++) {
            if (knocked_out[i]) {
                continue; // Skip if already knocked out
            }

            // Calculate the time at the end of this lap for competitor i
            int current_time = lap_times[i] * lap;

            // Check if this competitor is knocked out by the fastest competitor
            if (current_time > fastest_time * lap) {
                knocked_out[i] = 1; // Mark as knocked out
            }
        }
    }

    // Count competitors who are not knocked out
    int non_knocked_out_count = 0;
    for (int i = 0; i < N; i++) {
        if (!knocked_out[i]) {
            non_knocked_out_count++;
        }
    }

    return non_knocked_out_count;
}

int main() {
    int N, K;

    // Input reading
    scanf("%d %d", &N, &K);
    int lap_times[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &lap_times[i]);
    }

    // Get the result
    int result = count_non_knocked_out_competitors(N, K, lap_times);

    // Output the result
    printf("%d\n", result);

    return 0;
}