제출 #1181635

#제출 시각아이디문제언어결과실행 시간메모리
1181635rythm_of_knightStove (JOI18_stove)C++17
100 / 100
12 ms1480 KiB
#include <bits/stdc++.h> #define ar array #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector <int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; if (n == k) return cout << n, 0; vector <int> b; int ans = k; for (int i = 1; i < n; i++) b.push_back(a[i] - a[i - 1]); sort(all(b), greater<int>()); for (int i = k - 1; i + 1 < n; i++) ans += b[i]; cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...