Submission #529989

#TimeUsernameProblemLanguageResultExecution timeMemory
529989nguyentunglamStove (JOI18_stove)C++14
100 / 100
45 ms2868 KiB
#include<bits/stdc++.h> #define forin(i,a,b) for(int i=a; i <= b; i++) #define forde(i, a, b) for(int i = a; i <= b; i--) using namespace std; const int N = 1e5 + 10; long long a[N], b[N]; int main() { int n, k; cin >> n >> k; forin(i, 1, n) cin>>a[i]; long long res = a[n] + 1 - a[1]; forin(i, 2, n) b[i-1] = a[i] - a[i-1]; sort (b + 1, b + n, greater<int>()); k = min (k, n ) ; forin(i, 1, k-1 ) res -= b[i] - 1; cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...