Submission #1331776

#TimeUsernameProblemLanguageResultExecution timeMemory
1331776masterofcppStove (JOI18_stove)C++20
100 / 100
14 ms1992 KiB
/*
            ,___________________________________________/7_
           |-_______------. `\                             |
       _,/ | _______)     |___\____________________________|
  .__/`((  | _______      | (/))_______________=.
     `~) \ | _______)     |   /----------------_/
       `__y|______________|  /
       / ________ __________/
      / /#####\(  \  /     ))
     / /#######|\  \(     //
    / /########|.\______ad/`
   / /###(\)###||`------``
  / /##########||
 / /###########||
( (############||
 \ \####(/)####))
  \ \#########//
   \ \#######//
    `---|_|--`
       ((_))
        `-`
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define Fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define bigint __int128
#define int long long
#define double long double
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define stop(msg) {cout<<msg; return;}
#define stopp(msg, msg2) {cout<<msg<<msg2; return;}
#define all(aba) aba.begin(), aba.end()
#define rall(aba) aba.rbegin(), aba.rend()
#define take(aba) for (int abab=0; abab<aba.size(); abab++) cin>>aba[abab]
#define print(aba,sep) for (auto abab : aba) cout<<abab<<sep
#define pprint(aba,sep1,sep2) for (int abab=0; abab<aba.size(); abab++) cout<<aba[abab].F<<sep1<<aba[abab].S<<sep2
#define line "-------------------\n"
#define nline "\n-------------------\n"
#define linen "-------------------\n"

/// find_by_order (index), order_of_key (lower bound)
template<typename t>
using indexed_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename t>
using indexed_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int rand(int l, int r) {return rng()%(r-l+1)+l;}

double estimate_time(double n) {
    double a = 7.1e-9, b = 0.02;
    return max((double)0, a*n+b);
}

// O(1e8) = 1s.

const int MOD = (int)998244353;
const int N = (int)1005;
const int LG = (int)20;
const int INF = (int)4e18;

void solve(int cs){
    int n,k; cin>>n>>k;
    vector<int> a(n);
    take(a);

    vector<int> diff(n-1);
    for (int i=0; i<n-1; i++) diff[i] = a[i+1] - a[i] - 1;
    sort(all(diff));

    int ans = n;
    for (int i=0; i<n-k; i++) ans += diff[i];
    cout<<ans<<endl;
}

signed main(){
    //freopen("moocast.in", "r", stdin);
    //freopen("moocast.out", "w", stdout);
    Fast;
    int t=1;
    //cin>>t;
    for (int i=1; i<=t; i++) {
        solve(i);
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...