제출 #1141029

#제출 시각아이디문제언어결과실행 시간메모리
1141029SG2AlokStove (JOI18_stove)C++17
100 / 100
21 ms6884 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; typedef long long ll; using namespace __gnu_pbds; #define endl '\n' #define hitaf ios_base::sync_with_stdio(false); cin.tie(0); #define fi first #define se second template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag, tree_order_statistics_node_update>; const ll MOD = 1e9 + 7; const ll MOD1 = 998244353; const ll INF = 4500000000000000000LL; const ll mod1 = 6900000469; const ll mod2 = 698000002369; ll n, m, q, k, a[500005], b[500005], c[500005]; string s; vector<ll> adj[200005]; int main(){ hitaf int T = 1; // cin >> T; while(T--){ cin >> n >> k; priority_queue<ll> pq; for(int i = 1; i <= n; i++) cin >> a[i]; ll ans = a[n] - a[1] + 1; for(int i = 2; i <= n; i++) pq.push(a[i] - a[i - 1] - 1); ll seg = 1; while(seg < k){ ans -= pq.top(); pq.pop(); seg++; } cout << ans << endl; } return 0; } /* 1 2 2 3 = 6 3 5 = 6; */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...