#include <bits/stdc++.h>
using namespace std;
#define loop(x) for (int i = 0; i < x; i++)
int main()
{
int N, K;
cin >> N >> K;
// vector<int> T(N);
priority_queue<int> gaps;
int prevT = -1;
int matchesUsed = 0;
int burnTime = N;
loop(N)
{
int t;
cin >> t;
if (prevT == -1 || t - prevT > 1)
{
matchesUsed++;
if (prevT != -1)
{
gaps.push(prevT - t + 1); // -1 * gapSize
}
}
prevT = t;
// cin >> T[i];
}
while (matchesUsed > K)
{
int g = -gaps.top();
gaps.pop();
matchesUsed--;
burnTime += g;
}
cout << burnTime << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
37 ms |
892 KB |
Output is correct |
17 |
Correct |
45 ms |
1008 KB |
Output is correct |
18 |
Correct |
38 ms |
912 KB |
Output is correct |
19 |
Correct |
38 ms |
848 KB |
Output is correct |
20 |
Correct |
34 ms |
888 KB |
Output is correct |
21 |
Correct |
30 ms |
848 KB |
Output is correct |
22 |
Correct |
30 ms |
848 KB |
Output is correct |
23 |
Correct |
29 ms |
852 KB |
Output is correct |
24 |
Correct |
29 ms |
968 KB |
Output is correct |