Submission #88149

#TimeUsernameProblemLanguageResultExecution timeMemory
88149tieunhiStove (JOI18_stove)C++14
100 / 100
26 ms10376 KiB
#include <bits/stdc++.h> #define FOR(i, u, v) for (int i = u; i <= v; i++) #define FORD(i, v, u) for (int i = v; i >= u; i--) #define N 1000005 using namespace std; int n, k, a[N], b[N], res; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("INP.TXT", "r", stdin); cin >> n >> k; FOR(i, 1, n) cin >> a[i]; sort(a+1, a+n+1); FOR(i, 1, n-1) b[i] = a[i+1] - a[i]; sort(b+1, b+n); reverse(b+1, b+n); k--; res = a[n] - a[1] + 1; FOR(i, 1, k) res -= (b[i]-1); cout <<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...