Submission #548834

#TimeUsernameProblemLanguageResultExecution timeMemory
548834KiprasStove (JOI18_stove)C++17
0 / 100
0 ms212 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]; 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...