Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- priority_queue<int> pq;
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- cin >> n;
- for (int i = 0, x; i < n; ++i) {
- cin >> x;
- pq.push(x);
- }
- int64_t ans = 0;
- while (pq.size() >= 2) {
- int most = pq.top(); pq.pop();
- int second_most = pq.top(); pq.pop();
- int max_pair = min(most, second_most);
- if (max_pair > 1) max_pair /= 2; // adicionado
- most -= max_pair;
- second_most -= max_pair;
- ans += max_pair;
- if (most > 0) pq.push(most);
- if (second_most > 0) pq.push(second_most);
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement