Submission #476056

#TimeUsernameProblemLanguageResultExecution timeMemory
476056Vladth11Stove (JOI18_stove)C++14
100 / 100
28 ms2256 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <long double, pii> muchie; const ll NMAX = 100001; const ll VMAX = 1000001; const ll INF = (1LL << 59); const ll MOD = 998244353; const ll BLOCK = 318; const ll base = 31; const ll nr_of_bits = 21; int v[NMAX]; vector <int> a; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k, n, i; cin >> n >> k; k--; for(i = 1; i <= n; i++){ cin >> v[i]; } sort(v + 1, v + n + 1); ll maxim = v[n] - v[1] + 1; for(i = 2; i <= n; i++){ a.push_back(v[i] - v[i - 1] - 1); } sort(a.begin(), a.end()); while(a.size() && k--){ maxim -= a.back(); a.pop_back(); } cout << maxim; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...