제출 #1124878

#제출 시각아이디문제언어결과실행 시간메모리
1124878sinatbtfardStove (JOI18_stove)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> using namespace std; int main (){ ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector <int> a(n), dif; for (int &i : a) cin >> i; for (int i = 1; i < n; i++) dif.push_back(a[i] - a[i - 1]); sort(dif.begin(), dif.end()); int sum = 0; for (int i = 0; i < n - k; i++) sum += dif[i]; int ans = sum + k; for (int i = n - k; i < n - 1; i++){ sum += dif[i]; ans = min(ans, dif[i] + n - i); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...