Submission #1283252

#TimeUsernameProblemLanguageResultExecution timeMemory
1283252dev_pandey20Stove (JOI18_stove)C++20
0 / 100
1 ms332 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }

    // Sort the arrival times
    sort(T.begin(), T.end());

    int total_time = 0;
    int last_on_time = -1;

    for (int i = 0; i < N; i++) {
        // If the stove is off and we have matches left
        if (last_on_time == -1 || T[i] > last_on_time + 1) {
            if (K > 0) {
                // Turn on the stove at time T[i]
                last_on_time = T[i];
                total_time += 1;
                K--;
            }
        }
    }

    cout << total_time << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...