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;
long long n,k,i,v[100010],timp;
map<long long,long long>fr,fr2;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(i=1;i<=n;i++)
{
cin>>v[i];
if(i>1)
fr[-(v[i]-v[i-1])]++;
}
k--;
for(auto it:fr)
{
if(k==0)
break;
if(it.first==-1)
continue;
fr2[it.first]+=min(k,it.second);
k-=min(k,it.second);
}
timp=1;
for(i=2;i<=n;i++)
{
if(v[i]-v[i-1]==1)
timp++;
else
{
if(!fr2[v[i-1]-v[i]])
timp+=v[i]-v[i-1];
else
{
fr2[v[i-1]-v[i]]--;
timp++;
}
}
}
cout<<timp;
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... |