#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
struct guest
{
int start;
int end;
};
struct breakLength
{
int start;
int length;
};
int main()
{
int n; // Number of guests
int k; // Number of matches
cin >> n >> k;
vector<guest> guests(n);
vector<breakLength> breaks(n-1);
for (int i = 0; i < n; i++)
{
int temp = 0;
cin >> temp;
guests[i].start = temp;
guests[i].end = temp+1;
if (i > 0)
{
breaks[i-1].start = guests[i].start;
breaks[i-1].length = guests[i].start - guests[i-1].end; //Length of break between guests
}
}
//Order breaks by length
sort(breaks.begin(), breaks.end(), [](breakLength a, breakLength b) { return a.length > b.length; });
//Time from first guest arrives to last guest leaves
int totalTime = guests[n-1].end - guests[0].start;
//Number of breaks where stove can be turned off
int stoveOff = k - 1;
//Time stove is on
int stoveOn = totalTime;
//Remove the length of the longest breaks from the time the stove is on
for (int i = 0; i < stoveOff; i++)
{
stoveOn -= breaks[i].length;
}
cout << stoveOn << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
424 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
424 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
424 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
41 ms |
2952 KB |
Output is correct |
17 |
Correct |
34 ms |
2904 KB |
Output is correct |
18 |
Correct |
34 ms |
2908 KB |
Output is correct |
19 |
Correct |
34 ms |
2896 KB |
Output is correct |
20 |
Correct |
40 ms |
2904 KB |
Output is correct |
21 |
Correct |
34 ms |
2900 KB |
Output is correct |
22 |
Correct |
34 ms |
2908 KB |
Output is correct |
23 |
Correct |
33 ms |
2904 KB |
Output is correct |
24 |
Correct |
34 ms |
2952 KB |
Output is correct |