제출 #1290443

#제출 시각아이디문제언어결과실행 시간메모리
1290443urteraStove (JOI18_stove)C++20
100 / 100
15 ms1580 KiB
//Mert Akarca <3
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,k,temp,temp1,nk,ans;
vector <int> fark;

int32_t main() 
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>k;
    for(int j = 0; j<n; ++j)
    {
        cin>>temp;
        if(j != 0) fark.push_back(temp-(temp1+1));
        temp1 = temp;
    } 
    nk = fark.size();  
    sort(fark.begin(),fark.end());
   /* for(int j = 0; j<nk; ++j)
    {
        cout<<fark[j]<<" ";
    }*/
    for(int j = nk-1; k-1 != 0; --j)
    {
        fark[j] = 0;
        --k;
    }
    for(int j = 0; j<nk; ++j)
    {
        ans += fark[j];
    }
    cout<<ans+n;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...