제출 #1272721

#제출 시각아이디문제언어결과실행 시간메모리
1272721gazizmadi11Stove (JOI18_stove)C++20
20 / 100
1 ms652 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front #define F first #define S second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NE r < tl || tr < l #define double long double #define int long long using namespace std; const int N=2e5+7; const int mod=998244353; const int inf=2e9; void solve(){ int n, k; cin >> n >> k; int a[n+1]{}; vector<int>v; for(int i=1; i <= n; i++){ cin >> a[i]; v.pb(a[i]-a[i-1]-1); } sort(all(v)); int ans=a[n]-a[1]+1; for(int i=n-1; i > n-k; i--)ans -= v[i]; cout << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t=1; // cin >> t; while(t--)solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...