Submission #653412

#TimeUsernameProblemLanguageResultExecution timeMemory
653412Dec0DeddStove (JOI18_stove)C++14
100 / 100
49 ms1816 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l=-1; cin>>n>>k; vector<int> v; int ans=0, mn=1e9+1, mx=-1e9-1; for (int i=1; i<=n; ++i) { int a; cin>>a; mn=min(mn, a), mx=max(mx, a); if (l != -1) v.push_back(a-l-1); l=a; } ans=mx-mn+1; sort(v.begin(), v.end(), greater<int>()); for (int i=0; i<min((int)v.size(), k-1); ++i) ans-=v[i]; cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...