This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* بسم الله الرحمن الرحيم *
﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿
*/
/// author : "ASGA"
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ONLINE 0
#ifdef ONLINE_JUDGE
#undef ONLINE;
#define ONLINE 1
#endif
#define dbg(a) if(!ONLINE)cout << a << ' ';
const ll inf = 1e18;
signed main(){
ios_base::sync_with_stdio(0);cin.tie();
int n,k;cin >> n >> k;
vector <int> a(n);
for(int& i : a)cin >> i;
ll ans = a.back() + 1 - a[0];
multiset <int> s;
for(int i = 0;i + 1 < n;i++)s.insert(a[i + 1] - a[i]);
auto i = s.rbegin();
while(--k){ans -= (*i++);ans++;}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |