Submission #921405

#TimeUsernameProblemLanguageResultExecution timeMemory
921405AverageAmogusEnjoyerStove (JOI18_stove)C++17
100 / 100
14 ms2204 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> bool cmin(T &i, T j) { return i > j ? i=j,true:false; } template<class T> bool cmax(T &i, T j) { return i < j ? i=j,true:false; } const int nax = 100100; int a[nax],b[nax],n,k; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i=0;i<n;i++) { cin >> a[i]; } for (int i=0;i<n-1;i++) { b[i] = a[i+1]-a[i]-1; } sort(b,b+n-1); reverse(b,b+n-1); int ans = a[n-1] - a[0] + 1; for (int i=0;i<k-1;i++) { ans -= b[i]; } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...