제출 #266843

#제출 시각아이디문제언어결과실행 시간메모리
266843shinjanStove (JOI18_stove)C++14
100 / 100
42 ms2424 KiB
#include <iostream> #include <bits/stdc++.h> #define maxN 100001 using namespace std; int t[maxN]; vector <int> resh; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,k; cin>>n>>k; k--; for(int i=0;i<n;i++) { cin>>t[i]; } sort(t,t+n); long long ans=t[n-1]+1-t[0]; for(int i=1;i<n;i++) { resh.push_back(t[i-1]+1-t[i]); } sort(resh.begin(),resh.end()); int ind=0; while(k--) { ans+=resh[ind]; ind++; } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...