제출 #1300018

#제출 시각아이디문제언어결과실행 시간메모리
1300018libdeseeStove (JOI18_stove)C++20
100 / 100
15 ms2468 KiB
    #include <bits/stdc++.h>
    using namespace std;
    #define level_up ios::sync_with_stdio(false);cout.tie(nullptr)
    #define int long long
    #define pb push_back
    #define mk make_pair
    #define ent cout << '\n'
    #define F first
    #define S second
    #define all(s) s.begin(), s.end()
    #define ERR cout << "ERROR\n";
    #define yes cout << "YES\n"
    #define no cout << "NO\n"
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    string num = "123456789";
    string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const int ITERATIONS = 1e7;
    const int inf = 1e18;
    const int N = 5e9+5;
    const int NN = 5e15+10;
    const int modd = 1e9+7;
    const int k = 500;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


    void solve() {
        int n, k;
        cin >> n >> k;
        int a[n+10];
        for ( int i = 1; i <= n; i++ ) cin >> a[i];
        int ans = n;
        vector <int> v;
        for ( int i = 2; i <= n; i++ ) {
            v.pb(a[i] - a[i-1] - 1);
        }
        sort(all(v));
        for ( int i = 0; i < n - k; i++ ) ans += v[i];
        cout << ans;

    }
    
    signed main() {
        level_up;
    //    freopen("bridges.in", "r", stdin);
    //    freopen("bridges.out", "w", stdout);
        int T = 1;
    //    cin >> T;
        for ( int test = 1; test <= T; test++ ) {
            solve();
            ent;
        }

        return 0;       
    }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...