제출 #1115268

#제출 시각아이디문제언어결과실행 시간메모리
1115268staszic_ojuzStove (JOI18_stove)C++17
100 / 100
25 ms2128 KiB
#include<bits/stdc++.h> #ifdef _DEBUG #define ls(x) << x << ", " #define lv(x) << #x << ": " << flush << x << ", " #define pr(x) cout << "Line: " << __LINE__ << ", " x << endl; #else #define ls(x) #define lv(x) #define pr(x) ; #endif using namespace std; typedef unsigned int uint; bool cmp(uint a, uint b) { return a > b; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); uint n, k; cin >> n >> k; vector<uint> a(n); for (uint i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); uint last = a[0]; vector<uint> t(n); uint offset = 0, m = 0; for (uint i = 0; i < n; i++) { pr(lv(last) lv(a[i])) if (last == a[i]) { offset++; last = a[i]; continue; } t[i - offset] = a[i] - last - 1; pr(lv(last) lv(a[i] - last - 1)) last = a[i]; m++; } t.resize(m); k--; sort(t.begin(), t.end(), cmp); for (uint i = 0; i < m; i++) { pr(lv(i) lv(t[i])) } uint lenght = 0; for (uint i = k; i < m; i++) { lenght += t[i]; } cout << (lenght + n) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...