Submission #548836

#TimeUsernameProblemLanguageResultExecution timeMemory
548836KiprasStove (JOI18_stove)C++17
100 / 100
46 ms2636 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { ios_base::sync_with_stdio();cin.tie(nullptr); ll n, k; cin>>n>>k; vector<ll> a; for(int i = 0; i < n; i++){ ll aa; cin>>aa; a.push_back(aa); } vector<ll> s; for(int i = 0; i < n-1; i++){ s.push_back(a[i+1]-a[i]-1); } ll all=a[n-1]+1-a[0]; if(k>=n)cout<<n; else{ sort(s.begin(), s.end()); reverse(s.begin(), s.end()); for(int i = 0; i < k-1; i++){ //cout<<s[i]<<endl; all-=s[i]; } cout<<all; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...