Submission #373690

#TimeUsernameProblemLanguageResultExecution timeMemory
373690MertD014Stove (JOI18_stove)C++17
100 / 100
25 ms2052 KiB
#include<bits/stdc++.h> #define pb push_back #define pf push_front #define f1 first #define f2 second #define ll long long #define pii pair<int,int> #define fastio() cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false) //no scanf #define fileio(code) freopen("code.in","r",stdin);freopen("code.out","w",stdout) //file name using namespace std; //https://oj.uz/problem/JOI18_stove int n,k,x,y,ans,mn=INT_MAX,mx=INT_MIN; vector<int> v; int main(){ fastio(); cin>>n>>k; cin>>x; mn=min(mn,x); mx=max(mx,x); for(int i=1;i<n;i++){ cin>>y; mn=min(mn,y); mx=max(mx,y); v.pb(y-x-1); x=y; } sort(v.rbegin(),v.rend()); for(int i=0;i<k-1;i++) ans+=v[i]; cout<<mx-mn+1-ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...