Submission #1031394

#TimeUsernameProblemLanguageResultExecution timeMemory
1031394andrewpStove (JOI18_stove)C++14
100 / 100
14 ms3292 KiB
//Dedicated to my love, ivaziva #include <bits/stdc++.h> using namespace std; #define ll int64_t #define ar array #define dbg(x) cerr << #x << ": " << x << "\n"; const int mxN=1e5+1; ll n, k, a[mxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; --k; vector<ll> b; for(ll i=1; i<=n; ++i) cin >> a[i]; ll ans=a[n]-a[1]; for(ll i=2; i<=n; ++i) { b.push_back(a[i]-a[i-1]-1); } sort(b.begin(), b.end(), greater<int>()); for(int i=0; i<k; ++i) { ans-=b[i]; } cout << ans+1 << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...