#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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |