Submission #1267815

#TimeUsernameProblemLanguageResultExecution timeMemory
1267815ashraful_alamStove (JOI18_stove)C++20
100 / 100
13 ms1480 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; void solve() { //write your code here... int n, k, x = 0; cin >> n >> k; vector<int> a(n), b; for (auto &i : a) cin >> i; for (int i = 0; i < n; i++) { if (i == n - 1) x++; else if (a[i + 1] != a[i] + 1) { x++; b.push_back(a[i + 1] - a[i] - 1); } } if (k >= x) {cout << n << '\n'; return;} x -= k; sort(b.begin(), b.end()); for (int i = 0; i < x; i++) n += b[i]; cout << n << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll 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...