# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
668749 | mseebacher | Stove (JOI18_stove) | C++17 | 18 ms | 2308 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>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".ans").c_str(), "w", stdout);
}
#define MAXI (int)1e5
#define LSOne(S) ((S) & -(S))
#define MSB(S) __builtin_clz(S)
void solve(){
int n,k; cin >> n >> k;
int b[n];
for(int i = 0;i<n;i++){
cin >> b[i];
}
ll dis = b[n-1]-b[0]+1;
vector<int> diff;
for(int i = 1;i<n;i++){
diff.push_back(b[i]-b[i-1]-1);
}
sort(diff.rbegin(),diff.rend());
for(int i = 0;i+1<k;i++){
dis -= diff[i];
}
cout << dis;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout << fixed << setprecision(8);
int t = 1;
//cin >> t;
while(t){
solve();
t--;
cout << "\n";
}
}
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... |