Submission #1305958

#TimeUsernameProblemLanguageResultExecution timeMemory
1305958dobri_okeStove (JOI18_stove)C++20
100 / 100
15 ms2252 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define F first #define S second const int N = 2e5 + 5, inf = 1e9 + 1, mod = 1e9 + 7; int n, k, a[N], sum = 0; vector < int > v; void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 2; i <= n; i++) v.pb(a[i] - a[i - 1] - 1); sort(v.begin(), v.end()); //for(auto to : v) cout << to << ' '; int nn = v.size() - 1; for(int i = nn; i > nn - k + 1; i--) sum += v[i]; cout << (a[n] - a[1] + 1) - sum << '\n'; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("guard.in", "r", stdin); //freopen("guard.out", "w", stdout); int tt = 1; //cin >> tt; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...