Submission #1163412

#TimeUsernameProblemLanguageResultExecution timeMemory
1163412canhnam357Stove (JOI18_stove)C++20
100 / 100
15 ms2376 KiB
// source problem : #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define int long long #define lb lower_bound #define ub upper_bound #define MASK(i) (1LL << (i)) const int inf = 1e18; void ckmax(int& f, int s) { f = (f > s ? f : s); } void ckmin(int& f, int s) { f = (f < s ? f : s); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int &i : a) cin >> i; sort(all(a)); k--; vector<int> d; for (int i = 1; i < n; i++) d.push_back(a[i] - a[i - 1] - 1); sort(d.rbegin(), d.rend()); int ans = a[n - 1] - a[0] + 1; for (int i = 0; i < k; i++) ans -= d[i]; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...