Submission #755088

# Submission time Handle Problem Language Result Execution time Memory
755088 2023-06-09T11:43:16 Z otiko_lagadze Stove (JOI18_stove) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define pb push_back
#define endl '\n'
#define y1 y21
using namespace std;
const int inf = 1e9;
const int mxn = 2*1e5+11;
const int lg = 31;
const ll mod = 1e9+7;

void slve(){
    int n,k;
    cin>>n>>k;

    vector<int> a(n), b;
    for(int i=0; i<n; i++){
        cin>>a[i];

        if(i){
            b.pb(a[i] - a[i-1] - 1);
        }
    }

    int ans = a.back();
    sort(b.rbegin(), b.rend());
    for(int i=0; i<k-1; i++){
        ans -= b[i];
    }

    cout<<ans;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    ll T = 1;
    // cin>>T;
    while (T--) {
        slve();
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -