제출 #1179648

#제출 시각아이디문제언어결과실행 시간메모리
1179648patgraStove (JOI18_stove)C++20
100 / 100
35 ms5572 KiB
#include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 0; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define ll long long #define pb push_back using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; set<int> st; int x; rep(i, 0, n) cin >> x, st.insert(x); n = (int)st.size(); priority_queue<int> holes; auto prv = -1; repIn(i, st) { if(prv != -1) holes.push(i - prv - 1); prv = i; } auto ans = *prev(st.end()) - *st.begin() + 1; DC << ans << eol; int holesUsed = 0; while(holesUsed + 1 < k) { ans -= holes.top(), holes.pop(), holesUsed++; DC << ans << eol; } cout << ans << eol; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...