Submission #306925

#TimeUsernameProblemLanguageResultExecution timeMemory
306925mihai145Stove (JOI18_stove)C++14
100 / 100
101 ms2396 KiB
#include <iostream> #include <queue> using namespace std; const int NMAX = 1e5; int N, K, a[NMAX + 2]; priority_queue < int > pq; int main() { cin >> N >> K; for(int i = 1; i <= N; i++) cin >> a[i]; int ans = a[N] + 1 - a[1]; for(int i = 2; i <= N; i++) pq.push(a[i] - a[i - 1] - 1); for(int i = 1; i < K; i++) ans -= pq.top(), pq.pop(); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...