Submission #1276859

#TimeUsernameProblemLanguageResultExecution timeMemory
1276859LmaoLmaoStove (JOI18_stove)C++20
100 / 100
14 ms1228 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 5e5+5; const int INF = 1e9; const int MOD = 998244353; int a[N]; int b[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int n,k; cin >> n >> k; for(int i=1;i<=n;i++) { cin >> a[i]; if(i>1) { b[i-1]=a[i]-a[i-1]-1; } } sort(b+1,b+n,greater<>()); int ans=a[n]-a[1]+1; for(int i=1;i<k;i++) { ans-=b[i]; } cout << ans; return 0; } /* ██╗░░██╗██╗░░██╗░█████╗░███╗░░██╗░██████╗░ ░██████╗██╗██╗░░░██╗ ░█████╗░██╗░░░██╗████████╗███████╗ ██║░██╔╝██║░░██║██╔══██╗████╗░██║██╔════╝░ ██╔════╝██║██║░░░██║ ██╔══██╗██║░░░██║╚══██╔══╝██╔════╝ █████═╝░███████║███████║██╔██╗██║██║░░██╗░ ╚█████╗░██║██║░░░██║ ██║░░╚═╝██║░░░██║░░░██║░░░█████╗░░ ██╔═██╗░██╔══██║██╔══██║██║╚████║██║░░╚██╗ ░╚═══██╗██║██║░░░██║ ██║░░██╗██║░░░██║░░░██║░░░██╔══╝░░ ██║░╚██╗██║░░██║██║░░██║██║░╚███║╚██████╔╝ ██████╔╝██║╚██████╔╝ ╚█████╔╝╚██████╔╝░░░██║░░░███████╗ ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝░╚═════╝░ ╚═════╝░╚═╝░╚═════╝░ ░╚════╝░░╚═════╝░░░░╚═╝░░░╚══════╝ */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...