# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
481430 | Vovamatrix | Stove (JOI18_stove) | C++14 | 24 ms | 5452 KiB |
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;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define endl "\n"
#define MAXN 100007
ll a[MAXN];
vector<ll> v;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(i==0) v.pb(a[i]);
else if(a[i]-a[i-1]>1)
{
v.pb(a[i-1]+1);
v.pb(a[i]);
}
if(i==n-1) v.pb(a[i]+1);
}
int x=v.size()/2-k;
ll rez=0;
//cout<<x<<endl;
//for(auto q:v) cout<<q<<" ";cout<<endl;
for(int i=0;i<v.size()-1;i=i+2)
{
rez+=v[i+1]-v[i];
}
//cout<<rez<<endl;
if(x<=0) cout<<rez;
else
{
vector<ll> v1;
for(int i=2;i<v.size()-1;i=i+2)
{
v1.pb(v[i]-v[i-1]);
}
sort(v1.begin(),v1.end());
//for(auto q:v1) cout<<q<<" ";
//cout<<endl;
for(int i=0;i<x;i++) rez+=v1[i];
cout<<rez;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |