Submission #655018

#TimeUsernameProblemLanguageResultExecution timeMemory
655018happypotatoStove (JOI18_stove)C++17
100 / 100
49 ms2036 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans = a[n - 1] - a[0] + 1; int check[n - 1]; for (int i = 1; i < n; i++) check[i - 1] = a[i] - a[i - 1]; sort(check, check + n - 1, greater<int>()); for (int i = 0; i < k - 1; i++) ans -= check[i] - 1; cout << ans << endl; } int main() { solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...