Submission #487962

#TimeUsernameProblemLanguageResultExecution timeMemory
487962BY_KUTBILIMStove (JOI18_stove)C++17
100 / 100
20 ms2840 KiB
/* @AUTHOR: BY_KUTBILIM FILE CREATED: 17.11.2021 14:43:09 (GMT+6) */ #include <bits/stdc++.h> using namespace std; #define endl '\n' #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fi first #define se second #define pb push_back using ll = long long; using pii = pair<int, int>; void solve(){ int n, k; cin >> n >> k; long long a[n]; for(auto &e : a){ cin >> e; } long long b[n-1]; for(int i = 0; i < n-1; i++){ b[i] = a[i+1] - a[i]-1; } sort(b, b + n - 1); long long ans = n; for(int i = 0; i <n-k; i++)ans += b[i]; cout << ans << endl; } int main(){ ios::sync_with_stdio(0), cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...