제출 #647158

#제출 시각아이디문제언어결과실행 시간메모리
647158danikoynovStove (JOI18_stove)C++14
100 / 100
63 ms2032 KiB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e5 + 10;

int n, k, t[maxn], d[maxn];
void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i ++)
        cin >> t[i], d[i - 1] = (t[i - 1] + 1) - t[i];

    sort(d + 1, d + n);
    int ans = t[n] - t[1] + 1;
    for (int i = 1; i <= k - 1; i ++)
        ans += d[i];

    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...