Submission #768331

#TimeUsernameProblemLanguageResultExecution timeMemory
768331RifalStove (JOI18_stove)C++14
100 / 100
18 ms2316 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 998244353 #define INF 100000000 //#define ll long long ///#define cin fin ///#define cout fout #define fi first #define se second using namespace std; ///ofstream fout("herding.out"); ///ifstream fin("herding.in"); int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n, k, ans; cin >> n >> k; int arr[n]; ans = n; for(int i = 0; i < n; i++) cin >> arr[i]; sort(arr,arr+n); vector<int> dis; for(int i = 1; i < n; i++) { dis.push_back(arr[i]-arr[i-1]-1); } sort(dis.begin(),dis.end()); for(int i = 0; i < n-k; i++) ans += dis[i]; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...