제출 #1190594

#제출 시각아이디문제언어결과실행 시간메모리
1190594emil_aliyevvStove (JOI18_stove)C++20
100 / 100
12 ms2244 KiB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
#define Bismillah ios_base::sync_with_stdio(0);cin.tie(0);
#define indexed_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

const int N = 1e5 + 7;
const int INF = 1e18;
const int MOD = 998244353;

int n , k , a[N];

signed main()
{
    Bismillah;
    // freopen("closing.in", "r", stdin);
    // freopen("closing.out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int say = 1;
    for(int i = 2; i <= n; i++)
    {
        if(a[i] - a[i - 1] > 1) say++;
    }
    if(k >= say)
    {
        cout << n << endl;
        return 0;
    }
    int res = n;
    vector < int > v;
    for(int i = 2; i <= n; i++)
    {
        if(a[i] - a[i - 1] == 1)continue;
        v.push_back(a[i] - a[i - 1]);
    }
    sort(v.begin() ,v.end());
    for(int i = 0; i < (say - k); i++)
    {
        res += v[i] - 1;
    }
    cout << res << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...