#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;
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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
1 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 |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
1 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 |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
39 ms |
1744 KB |
Output is correct |
17 |
Correct |
38 ms |
1832 KB |
Output is correct |
18 |
Correct |
39 ms |
1776 KB |
Output is correct |
19 |
Correct |
37 ms |
1796 KB |
Output is correct |
20 |
Correct |
33 ms |
1788 KB |
Output is correct |
21 |
Correct |
30 ms |
1728 KB |
Output is correct |
22 |
Correct |
29 ms |
1724 KB |
Output is correct |
23 |
Correct |
30 ms |
1708 KB |
Output is correct |
24 |
Correct |
29 ms |
1788 KB |
Output is correct |