Submission #854813

#TimeUsernameProblemLanguageResultExecution timeMemory
854813hungt58Stove (JOI18_stove)C++14
100 / 100
17 ms5720 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long #define TIME (1.0 * clock() / CLOCKS_PER_SEC) typedef pair<ll,ll> ii; const ll maxn=300010; ll n,p[maxn],a[maxn]; priority_queue<ii,vector<ii>,greater<ii>> q; int root(int i) { if (p[i] == i) return i; return root(p[i]); } void merge (long i,long j) { p[root(i)]=p[root(j)]; } ll b[maxn],k; int main() { ios_base :: sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>k; for (ll i=1;i<=n;i++) cin>>a[i]; sort (a+1,a+n+1); for (ll i=1;i<n;i++) b[i]=a[i+1]-a[i]; ll res=0; n--; sort (b+1,b+n+1); for (ll i=1;i<=n-k+1;i++) res=res+b[i]; res+=k; cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...