//
// Created by Tooster on 20.11.2017.
//
#include <queue>
#include <cstdio>
using namespace std;
priority_queue<int, vector<int>, greater<int> > Q;
int main() {
int n;
scanf("%d", &n);
while (n--) {
int a;
scanf("%d", &a);
Q.push(a);
}
int last = 0;
while (!Q.empty()) {
if(last != 0) {
if (last == Q.top()) {
Q.pop();
Q.push(last + 1);
last = 0;
} else {
last = Q.top();
Q.pop();
}
} else {
last = Q.top();
Q.pop();
}
}
printf("%d", last);
return 0;
}
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 33 34 35 36 37 38 39 | // // Created by Tooster on 20.11.2017. // #include <queue> #include <cstdio> using namespace std; priority_queue<int, vector<int>, greater<int> > Q; int main() { int n; scanf("%d", &n); while (n--) { int a; scanf("%d", &a); Q.push(a); } int last = 0; while (!Q.empty()) { if(last != 0) { if (last == Q.top()) { Q.pop(); Q.push(last + 1); last = 0; } else { last = Q.top(); Q.pop(); } } else { last = Q.top(); Q.pop(); } } printf("%d", last); return 0; } |
English