제출 #1283148

#제출 시각아이디문제언어결과실행 시간메모리
1283148nemkhoStove (JOI18_stove)C++20
100 / 100
15 ms1736 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 5; ll a[N], ans; int n, k; vector <int> tmp; void inp() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; } void solve() { for (int i = 2; i <= n; i++) tmp.push_back(a[i] - a[i-1] - 1); sort(tmp.begin(), tmp.end(), greater<int>()); for (int i = 0; i < min(k-1, (int)tmp.size()); i++) ans += tmp[i]; cout << a[n] - a[1] + 1 - ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); inp(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...