제출 #1196654

#제출 시각아이디문제언어결과실행 시간메모리
1196654andrejikusStove (JOI18_stove)C++20
100 / 100
12 ms1424 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) const int N = 1e5 + 3; int t[N]; void solve() { int n, k; cin >> n >> k; vector<int> dif; for (int i = 1; i <= n; i++) { cin >> t[i]; if (i == 1) continue; dif.push_back(t[i]-1-t[i-1]); } sort(dif.begin(), dif.end(), greater<>()); int ans = t[n]+1-t[1]; for (int i = 0; i < k-1; i++) ans -= dif[i]; cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int t=1; //cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...