Submission #740024

#TimeUsernameProblemLanguageResultExecution timeMemory
740024mzvStove (JOI18_stove)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> #define ccd ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define endl '\n' using namespace std; /* ------------------------ hi lol ------------------------ */ string s; ll n,k,ans,arr[100'001]; priority_queue<ll> pq; bool done=false; int main() { ccd cin >> n >> k; for (int i=1;i<=n;i++) { cin >> arr[i]; if (i==1&&!done) { if (arr[1]!=1) { pq.push(arr[1]-1); } done=1; } if (i>1) { if (arr[i]-arr[i-1]>1) { pq.push(arr[i]-arr[i-1]-1); } } } ans=arr[n]; if (n==1) { cout << ans-pq.top() << endl; return 0; } k--; // cout << ans << endl; // while (!pq.empty()) { // cout << pq.top() << " "; // pq.pop(); // } cout << endl; while (k&&!pq.empty()) { ans-= pq.top(); pq.pop(); k--; // cout << ans << " "; } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...