Submission #548837

#TimeUsernameProblemLanguageResultExecution timeMemory
548837Specialistas13Stove (JOI18_stove)C++17
100 / 100
47 ms2252 KiB
#include <bits/stdc++.h> using namespace std; int n, k; long long t[200000]; vector<long long> dist; long long sum=0; int main() { cin>>n>>k; for (int i=0; i<n; i++){ cin>>t[i]; } sum=t[n-1]-t[0]+1; if (k==1){ cout<<t[n-1]-t[0]+1; } else { for (int i=1; i<n; i++){ dist.push_back(t[i]-t[i-1]-1); } sort(dist.begin(), dist.end()); reverse(dist.begin(), dist.end()); for (int i=0; i<k-1; i++){ sum-=dist[i]; } cout<<sum; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...