제출 #684063

#제출 시각아이디문제언어결과실행 시간메모리
684063vjudge1Stove (JOI18_stove)C++14
100 / 100
18 ms2796 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define all(a) a.begin(), a.end() typedef long long ll; typedef pair<int, int> ii; const int N = 1e5 + 5; const int mod = 1e9 + 7; int n, k; ll res, a[N], b[N]; void solve() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) b[i] = a[i + 1] - a[i] - 1; a[n] = a[n] - a[1] + 1; sort(b + 1, b + n, greater<ll>()); for(int i = 1; i < k; i++) a[n] -= b[i]; cout << a[n]; } signed main() { cin.tie(0)->sync_with_stdio(0); int 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...