제출 #1241905

#제출 시각아이디문제언어결과실행 시간메모리
1241905ngonamkhanhStove (JOI18_stove)C++20
100 / 100
16 ms1864 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<ll> xet; xet.reserve(n - 1); for (int i = 0; i + 1 < n; i++) { xet.push_back(a[i + 1] - a[i] - 1); } sort(xet.begin(), xet.end()); ll ans = n; for (int i = 0; i < n - k; i++) { ans += xet[i]; } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...