제출 #870979

#제출 시각아이디문제언어결과실행 시간메모리
870979marcidStove (JOI18_stove)C++17
20 / 100
1 ms412 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n, k; cin >> n >> k; vector<int> a(n+1, 0); vector<pair<int,int>> b(n+1, {0,0}); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 1; i <= n; i++) { b[i].first = abs(a[i-1]-a[i])-1; b[i].second = i; } sort(b.rbegin(), b.rend()); int sum = a[n]-a[1]+1; for (int i = 0; i < k-1; i++) { sum -= b[i].first; } cout << sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...