Submission #587333

#TimeUsernameProblemLanguageResultExecution timeMemory
587333FidanStove (JOI18_stove)C++17
100 / 100
35 ms3228 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll num=(1e9)+7; const ll N=4*(1e5)+10; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n, k, i; cin>>n>>k; vector<ll> t(n); for(i=0; i<n; i++){ cin>>t[i]; } sort(t.begin(), t.end()); vector<ll> v; for(i=1; i<n; i++){ v.push_back(t[i]-t[i-1]-1); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); ll l=t[n-1]+1-t[0]; for(i=0; i<k-1; i++){ l-=v[i]; } cout<<l; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...