# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482833 | 2021-10-26T13:53:13 Z | glome | Stove (JOI18_stove) | C++17 | 1 ms | 204 KB |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,k; cin >> n >> k; vector<pair<int, int>> d; vector<int> y(n); for (int i = 0; i<n; i++) { cin >> y[i]; } for (int i = 0; i<n-1; i++) { if(y[i] + 1 == y[i + 1]) { continue; } d.push_back({y[i] + 1, y[i+1] - 1}); } sort(d.begin(), d.end(), [&] (pair<int, int> A, pair<int, int> B) { return A.second - A.first > B.second - B.first; }); map<int, bool> mark; for (int i = k - 1; i<d.size(); i++) { mark[d[i].first - 1] = 1; } int ans = 0; for (int i = 0; i<n - 1; i++) { if(mark[y[i]]) { if(i == 0) { ans += (y[i + 1] + 1) - y[i]; continue; } if(mark[y[i-1]]) { ans += y[i + 1] - y[i]; } else { ans +=( y[i + 1] + 1) - y[i]; } } else { ans++; } } if(n >= 2) { if(!mark[y[n-2]]) { ans++; } } cout << ans << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |