Submission #114408

#TimeUsernameProblemLanguageResultExecution timeMemory
114408lycStove (JOI18_stove)C++14
100 / 100
20 ms2176 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef pair<ii, int> ri3; #define mp make_pair #define pb push_back #define fi first #define sc second #define SZ(x) (int)(x).size() #define ALL(x) begin(x), end(x) #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define RFOR(i, a, b) for (int i = a; i >= b; --i) int main() { //freopen("in.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int t[n]; FOR(i,0,n-1){ cin >> t[i]; } int diff[n-1]; FOR(i,1,n-1){ diff[i-1] = t[i]-1-t[i-1]; } sort(diff, diff+n-1, greater<int>()); int ans = t[n-1]-t[0]+1; FOR(i,0,k-2){ ans -= diff[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...