# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330744 | 2020-11-26T12:52:11 Z | M_W | Stove (JOI18_stove) | C++14 | 1 ms | 364 KB |
#include <bits/stdc++.h> using namespace std; #define ii pair<int, int> struct cmp{ bool operator()(const ii &a, const ii &b) const{ return abs(a.first - a.second) < abs(b.first - b.second); } }; int g[100100]; int main(){ priority_queue<ii, vector<ii>, cmp> pq; int N, K, cur, old, maxt = INT_MIN; scanf("%d %d", &N, &K); for(int i = 0; i < N; i++){ scanf("%d", &g[i]); } sort(g, g + N); old = g[0]; for(int i = 1; i < N; i++){ pq.push(make_pair(old + 1, g[i])); old = g[i]; maxt = max(maxt, g[i] + 1); } K--; vector<int> v; while(!pq.empty() && K > 0){ int s = pq.top().first; int e = pq.top().second; pq.pop(); v.push_back(s); v.push_back(e); K--; } v.push_back(1); v.push_back(maxt); sort(v.begin(), v.end()); int sz = v.size(); int tuse = 0; for(int i = 0; i < sz; i += 2){ tuse += v[i + 1] - v[i]; } printf("%d", tuse); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |