This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#define forn(i,n) for(int i=0;i<n;++i)
#define pb(x) push_back(x)
#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pi pair<int,int>
#define f first
#define s second
#define int long long
const int inf = 1e18;
const int mod = 1e9+7;//998244353;
using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int n,k; cin>>n>>k;
vii(a,n);
int cnt=0;
int ans=n;
multiset<int> s;
forn(i,n-1) s.insert(a[i+1]-a[i]-1);
while (s.size()>=k) {
ans+=*s.begin();
s.erase(s.begin());
}
cout<<ans;
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
stove.cpp: In function 'void solve()':
stove.cpp:31:17: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
31 | while (s.size()>=k) {
| ^
stove.cpp:27:6: warning: unused variable 'cnt' [-Wunused-variable]
27 | int cnt=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... |