# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1228810 | khoingu | Stove (JOI18_stove) | C++20 | 0 ms | 328 KiB |
#include <bits/stdc++.h>
#define ll long long
#define fi(i,a,b) for(int i = a; i <= b; i ++)
using namespace std;
const ll maxN = 1e5 + 5;
int n, k, t[maxN], ans = 0;
bool vis[maxN];
vector <int> tim;
signed main() {
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i ++) {
cin >> t[i];
vis[t[i] + 1] = true;
}
ans = t[n] + 1 - t[1];
int cnt = 0;
for(int i = 1; i <= t[n] + 1; i ++) {
if (!vis[i])
cnt ++;
else {
if (cnt != 0) {
tim.push_back(cnt);
cnt = 0;
}
}
}
sort(tim.rbegin(), tim.rend());
//for(auto x : tim) cout << x << ' ';
k --;
while (k > 0 and !tim.empty()) {
ans -= tim[0];
//cout << tim[0] << " ";
tim.erase(tim.begin());
k --;
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |