Submission #256503

#TimeUsernameProblemLanguageResultExecution timeMemory
256503iliccmarkoStove (JOI18_stove)C++14
100 / 100
43 ms2552 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" int n, k; vector<int> t; vector<int> raz; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>k; for(int i = 1;i<=n;i++) { int a; cin>>a; t.push_back(a); } sort(t.begin(),t.end()); for(int i = 1;i<(int)t.size();i++) { raz.push_back(t[i]-t[i-1]-1); } sort(raz.begin(),raz.end(),greater<int>()); int sum = 0; for(int i = 0;i<k-1;i++) sum+=raz[i]; cout<<t[n-1] - t[0] + 1 - sum; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...