This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
string s;
void test_case() {
cin>>n>>k;
int arr[n];
for (int i=0; i<n; i++) {
cin>>arr[i];
}
vector<pair<int,int>> v;
int l=0;
int r=0;
for (int i=1; i<n; i++) {
if (arr[i]==arr[i-1]) {
r++;
}
else {
v.pb({arr[l],arr[r]});
l=i;
r=i;
}
}
v.pb({arr[l],arr[r]});
m=v.size();
vector<int> p;
for (int i=0; i<m; i++) {
//cout<<v[i].f<<" "<<v[i].s<<endl;
}
for (int i=1; i<m; i++) {
p.pb(v[i].f-v[i-1].s-1);
}
sort(all(p));
int ans=n;
for (int i=0; i<min(m-1,n-k); i++) {
ans+=p[i];
}
cout<<ans<<endl;
}
main () {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
T=1;
//cin>>T;
while (T--) {
test_case();
}
}
Compilation message (stderr)
stove.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
stove.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main () {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |