# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
679384 |
2023-01-08T07:44:29 Z |
Duy_e |
Stove (JOI18_stove) |
C++14 |
|
28 ms |
6100 KB |
#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i --)
using namespace std;
const long long N = 1e5 + 5;
ll n, a[N], k;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
rep(i, 1, n) cin >> a[i];
vector <pii> vi;
vector <pii> pos;
vi.push_back({a[1], a[1] + 1});
ll ans = 0;
rep(i, 2, n) {
if (a[i] == vi.back().nd) {
vi.back().nd ++;
continue;
}
vi.push_back({a[i], a[i] + 1});
}
int cnt = 0;
for (pii x: vi) {
ans += x.nd - x.st;
cnt ++;
}
rep(i, 1, (int)vi.size() - 1)
pos.push_back({vi[i].st - vi[i - 1].nd, i});
sort(pos.begin(), pos.end());
int j = 0;
while (cnt > k) {
ans += pos[j].st;
j ++;
cnt --;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
476 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
476 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
28 ms |
5912 KB |
Output is correct |
17 |
Correct |
28 ms |
5948 KB |
Output is correct |
18 |
Correct |
23 ms |
5920 KB |
Output is correct |
19 |
Correct |
25 ms |
6000 KB |
Output is correct |
20 |
Correct |
22 ms |
5904 KB |
Output is correct |
21 |
Correct |
24 ms |
5888 KB |
Output is correct |
22 |
Correct |
23 ms |
5956 KB |
Output is correct |
23 |
Correct |
23 ms |
5976 KB |
Output is correct |
24 |
Correct |
25 ms |
6100 KB |
Output is correct |