제출 #304609

#제출 시각아이디문제언어결과실행 시간메모리
304609vishesh312Stove (JOI18_stove)C++17
100 / 100
28 ms2432 KiB
#include <bits/stdc++.h> using namespace std; #define deb(x) cerr << #x << " = " << x << "\n"; #define deb2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << "\n"; #define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n"; #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() typedef long long ll; void solve() { int n, k; cin >> n >> k; vector<int> ent(n); for (int i = 0; i < n; ++i) { cin >> ent[i]; } priority_queue<int> pq; sort(all(ent)); for (int i = 0; i < n-1; ++i) { pq.push(ent[i+1] - ent[i] - 1); } int a = 0; for (int i = 0; i < k-1 && !pq.empty(); ++i) { a+= pq.top(); pq.pop(); } cout << (ent[n-1] - ent[0] - a + 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll tc = 1; //cin >> tc; while(tc--) { solve(); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...