Submission #1125368

#TimeUsernameProblemLanguageResultExecution timeMemory
1125368phoopStove (JOI18_stove)C++20
100 / 100
16 ms1096 KiB
#include<bits/stdc++.h> using namespace std; int a[1000100],b[1000100]; int main(){ cin.tie(0)->sync_with_stdio(0); int n,k,mx=INT_MIN,mn=INT_MAX; cin>>n>>k; for(int i=1;i<=n;i++){ cin>>a[i]; mx=max(mx,a[i]); mn=min(mn,a[i]); if(i>1){ b[i-1]=a[i]-a[i-1]-1; } } sort(b+1,b+n+1,greater<int>()); int total=(mx+1-mn); for(int i=1;i<=k-1;i++) total-=b[i]; cout<<total; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...