Submission #842265

#TimeUsernameProblemLanguageResultExecution timeMemory
842265ereringStove (JOI18_stove)C++17
100 / 100
16 ms2268 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pb push_back #define ll long long #define int ll const long long inf=1e18; const int MOD=1e9+7; const int N=2e5+5; signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,k; cin>>n>>k; vector<int> v; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; if(i>0)v.pb(a[i]-a[i-1]-1); } int ans=a[n-1]-a[0]+1; sort(v.begin(),v.end()); for(int i=n-2;i>=n-k;i--)ans-=v[i]; cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...