제출 #1248546

#제출 시각아이디문제언어결과실행 시간메모리
1248546antonnStove (JOI18_stove)C++20
100 / 100
11 ms584 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 7; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; ll ans = a[n] - a[1] + 1; for (int i = 1; i < n; ++i) a[i] = a[i + 1] - a[i] - 1; sort(a + 1, a + n); reverse(a + 1, a + n); for (int i = 1; i < k; ++i) ans -= a[i]; cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...