Submission #364225

#TimeUsernameProblemLanguageResultExecution timeMemory
364225RainbowbunnyStove (JOI18_stove)C++17
100 / 100
28 ms3328 KiB
#include <iostream> #include <queue> #include <algorithm> #include <utility> #include <vector> int n, k; long long t[100005]; std::priority_queue <long long, std::vector <long long>, std::greater <long long> > pq; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); std::cin >> n >> k; for(int i = 1; i <= n; i++) { std::cin >> t[i]; } for(int i = 1; i < n; i++) { pq.push(t[i + 1] - t[i] - 1); } long long ans = n; for(int i = 1; i <= n - k; i++) { ans += pq.top(); pq.pop(); } std::cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...