Submission #41205

#TimeUsernameProblemLanguageResultExecution timeMemory
41205MatheusLealVStove (JOI18_stove)C++14
100 / 100
70 ms2240 KiB
#include <bits/stdc++.h> #define N 100005 #define f first #define s second using namespace std; typedef long long ll; typedef pair<int, int> pii; int n, k, v[N]; vector<ll> vet; int main() { cin>>n>>k; for(int i = 1; i <= n; i++) cin>>v[i]; sort(v + 1, v + n + 1); for(int i = 1; i < n; i++) vet.push_back(v[i] - v[i + 1]); sort(vet.begin(), vet.end()); ll ans = v[n] - v[1] + k; for(int i = 0; i < k - 1; i++) ans += vet[i]; cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...