Submission #586449

#TimeUsernameProblemLanguageResultExecution timeMemory
586449SharkyStove (JOI18_stove)C++17
100 / 100
22 ms3228 KiB
#include <bits/stdc++.h> using namespace std; #define int long long using vi = vector<int>; using vb = vector<bool>; using pi = pair<int, int>; #define pb push_back #define all(x) x.begin(), x.end() #define FOR(i, a, b) for (int i = (int) a; i < (int) b; i++) #define rep(i, n) for (int i = 0; i < (int) n; i++) #define rep1(i, n) for (int i = 1; i <= (int) n; i++) #define sz(x) (int) x.size() #define fi first #define se second #define rd(a, sz) rep(i, n) cin >> a[i]; #define rd1(a, sz) rep1(i, n) cin >> a[i]; void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << '}';} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__) #else #define debug(...) #endif template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int MOD = 1e9 + 7; const int inf = 1e18; void solve(int tc) { int n, k, cnt = 1; cin >> n >> k; int ans = n; vector<int> t(n); priority_queue<int, vector<int>, greater<int>> q; rd(t, n); for (int i = 1; i < n; i++) { if (t[i] - t[i-1] != 1) { cnt++; q.push(t[i] - t[i-1] - 1); } } while (!q.empty() && cnt > k) { cnt--; ans += q.top(); q.pop(); } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int tt = 1; // cin >> tt; rep1(i, tt) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...