Submission #1310754

#TimeUsernameProblemLanguageResultExecution timeMemory
1310754somefolkStove (JOI18_stove)C++20
100 / 100
14 ms2368 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void solve(){ int n, k; cin >> n >> k; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; vector<int> diff; for(int i = 1; i < n; i++){ diff.push_back(a[i]-a[i-1]-1); } sort(diff.rbegin(), diff.rend()); int total = a[n-1] - a[0] + 1; for(int i = 0; i < k-1; i++){ total -= diff[i]; } cout << total << endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...