# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
55248 |
2018-07-06T17:53:34 Z |
shoemakerjo |
Stove (JOI18_stove) |
C++14 |
|
39 ms |
10532 KB |
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
int n, k;
int nums[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int ans = 0;
vector<int> diffs;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> nums[i];
if (i) ans += nums[i]-nums[i-1];
if (i) diffs.push_back(nums[i]-nums[i-1]-1);
}
ans++; //need to be one past the end
sort(diffs.begin(), diffs.end());
reverse(diffs.begin(), diffs.end());
for (int i = 0; i < k-1; i++) {
ans -= diffs[i];
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
444 KB |
Output is correct |
5 |
Correct |
2 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
444 KB |
Output is correct |
5 |
Correct |
2 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
3 ms |
812 KB |
Output is correct |
13 |
Correct |
3 ms |
812 KB |
Output is correct |
14 |
Correct |
3 ms |
828 KB |
Output is correct |
15 |
Correct |
3 ms |
836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
444 KB |
Output is correct |
5 |
Correct |
2 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
3 ms |
812 KB |
Output is correct |
13 |
Correct |
3 ms |
812 KB |
Output is correct |
14 |
Correct |
3 ms |
828 KB |
Output is correct |
15 |
Correct |
3 ms |
836 KB |
Output is correct |
16 |
Correct |
25 ms |
2804 KB |
Output is correct |
17 |
Correct |
25 ms |
3832 KB |
Output is correct |
18 |
Correct |
27 ms |
4684 KB |
Output is correct |
19 |
Correct |
24 ms |
5648 KB |
Output is correct |
20 |
Correct |
39 ms |
6748 KB |
Output is correct |
21 |
Correct |
25 ms |
7680 KB |
Output is correct |
22 |
Correct |
24 ms |
8620 KB |
Output is correct |
23 |
Correct |
28 ms |
9568 KB |
Output is correct |
24 |
Correct |
24 ms |
10532 KB |
Output is correct |