Submission #885848

#TimeUsernameProblemLanguageResultExecution timeMemory
885848BBart888Stove (JOI18_stove)C++14
100 / 100
19 ms2636 KiB
#include <cstdio> #include <iostream> #include <vector> #include <list> #include <string> #include <set> #include <map> #include <algorithm> #include <fstream> #include <cmath> #include <queue> #include <stack> #include <cassert> #include <cstring> #include <climits> #include <functional> #include<cstdlib> //#include "arc.h" using namespace std; typedef pair<int, int> PII; typedef vector<int> VI; typedef long long LL; const int MAXN = 2e5 + 11; using ll = long long; typedef vector<int> lnum; const int base = 1e9; const ll mod1 = 1e9 + 7; const ll mod2 = 1000000021; const ll P = 31; /* void setIO(string name = "") { cin.tie(0)->sync_with_stdio(0); // see /general/fast-io if ((name.size())) { freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output freopen((name + ".out").c_str(), "w", stdout); } } */ int n, k; priority_queue<int> pq; int a[MAXN]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); //setIO("time"); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int ans = a[n - 1] + 1 - a[0]; for (int i = 1; i < n; i++) pq.push(a[i] - a[i - 1] - 1); for (int i = 0; i < k-1 && pq.size(); i++) { int val = pq.top(); pq.pop(); ans -= val; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...