Submission #970637

#TimeUsernameProblemLanguageResultExecution timeMemory
970637Roumak77Stove (JOI18_stove)C++17
100 / 100
16 ms2908 KiB
#pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize("-Ofast") #include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <vector> #include <limits> #include <cmath> #include <stack> #include <queue> #include <map> #include <math.h> using namespace std; using ll = long long; void solve(){ ll n, k; cin >> n >> k; if(n == 1){ cout << 1 << endl; return; } vector<ll> list_n(n, 0); for(ll i = 0; i < n; i++){ cin >> list_n[i]; } vector<ll> diff(n - 1, 0); for(ll i = 0; i < n - 1; i++){ diff[i] = list_n[i + 1] - list_n[i]; } sort(diff.begin(), diff.end()); ll total = n; for(ll i = 0; i < n - k; i++){ total += diff[i] - 1; } cout << total; } int main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); ll t = 1; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...