#include<bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::priority_queue<int, std::vector<int>, std::greater<int> > q;
int x;
while(n --> 0) {
std::cin >> x;
q.push(x);
}
int prev = -1;
while(!q.empty()) {
int cur = q.top();
// std::cout << cur << std::endl;
q.pop();
if(prev != -1) {
if(prev == cur) {
q.push(prev + 1);
prev = -1;
continue;
}
}
prev = cur;
}
std::cout << prev << std::endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<bits/stdc++.h> int main() { int n; std::cin >> n; std::priority_queue<int, std::vector<int>, std::greater<int> > q; int x; while(n --> 0) { std::cin >> x; q.push(x); } int prev = -1; while(!q.empty()) { int cur = q.top(); // std::cout << cur << std::endl; q.pop(); if(prev != -1) { if(prev == cur) { q.push(prev + 1); prev = -1; continue; } } prev = cur; } std::cout << prev << std::endl; } |
English