Submission #887904

#TimeUsernameProblemLanguageResultExecution timeMemory
887904oblantisStove (JOI18_stove)C++17
100 / 100
15 ms1884 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, int> pdi; const int inf = 1e9 + 10000; const int mod = 1e9+7; const int maxn = 5e5 + 12; void solve() { int n, k; cin >> n >> k; int t[n], p[n]; k = n - k; int ans = n; for(int i = 0; i < n; i++) { cin >> t[i]; if(i)p[i] = t[i] - t[i - 1] - 1; } sort(p + 1, p + n); for(int i = 1; i <= k; i++) { ans += p[i]; } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int times = 1; //cin >> times; for(int i = 1; i <= times; i++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...