Submission #1171792

#TimeUsernameProblemLanguageResultExecution timeMemory
1171792h1440Stove (JOI18_stove)C++20
100 / 100
12 ms2012 KiB
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fore(i,a,b) for(lli i = (a), abcdxd = (b); i < abcdxd; i++)
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ENDL '\n'
#define sz(s) lli((s).size())
#define pb push_back
using namespace std;
typedef long long lli;
// typedef long long LLI;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef long double ld;
#define deb(x) cout << #x << ": " << x << endl;
#define BIGLLI __int128

void solve(){
  lli n, k; cin >> n >> k;
  vi b(n); for (auto & i : b) cin >> i;
  lli ans = b[n-1] + 1 - b[0], res = 0;
  vi v(n-1); fore(i,1,n) v[i-1] = b[i] - b[i - 1] - 1;
  sort(rall(v));
  fore(i,0,k-1) res += v[i];
  cout << ans - res << endl;
}

int main(){ _
  // lli t; cin >> t;
  // while (t--)
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...