# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1099959 | Trn115 | Stove (JOI18_stove) | C++11 | 15 ms | 3028 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define all(v) v.begin(), v.end()
using namespace std;
inline void setio(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if (fopen((name+".INP").c_str(), "r")) {
freopen((name+".INP").c_str(), "r", stdin);
freopen((name+".OUT").c_str(), "w", stdout);
}
}
int n, k;
vector<int> t;
inline void input() {
cin >> n >> k;
t.resize(n);
for (int &i : t) cin >> i;
}
inline void solve() {
vector<int> g(n-1);
for (int i = 0; i < n-1; ++i) g[i] = t[i+1] - t[i] - 1;
int total = t.back() - t.front() + 1;
sort(all(g), greater<int>());
cout << total - accumulate(g.begin(), g.begin()+(k-1), 0);
}
signed main() {
setio();
input();
solve();
}
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... |