# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
996384 | presko | Stove (JOI18_stove) | C++14 | 0 ms | 348 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<iostream>
#include<vector>
#include<algorithm>
#define MAXN 100010
using namespace std;
vector<int> order;
int a[MAXN];
int main()
{
int n,k;
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(i>1)order.push_back(a[i]-a[i-1]);
}
if(k==1){cout<<a[n]+1-a[1]<<"\n";return 0;}
if(k==n){cout<<n+1<<"\n";return 0;}
sort(order.begin(),order.end());
int cntr=0,ans=0;
for(int i=0;i<order.size();i++)
{
ans+=order[i]+1;
cntr++;
if(i>0)
{
if(order[i-1]==1)ans--;
}
if(cntr>=n-k)break;
}
cout<<ans+k-1<<"\n";
}
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... |