Submission #715864

#TimeUsernameProblemLanguageResultExecution timeMemory
715864TheSahibStove (JOI18_stove)C++17
100 / 100
50 ms1796 KiB
#include <bits/stdc++.h> #define ll long long #define oo 1e9 #define pii pair<int, int> using namespace std; const int MAX = 1e5 + 5; int n, k; int arr[MAX]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); vector<int> ranges; for (int i = 0; i < n - 1; i++) { ranges.emplace_back(arr[i + 1] - arr[i] - 1); } int ans = arr[n - 1] - arr[0] + 1; sort(ranges.begin(), ranges.end()); reverse(ranges.begin(), ranges.end()); for (int i = 0; i < k - 1; i++) { ans -= ranges[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...