#include <iostream> #define NOMINALY 202000 using namespace std; void zeruj(int a[], int n) { for (int i = 0; i < n; i++) a[i] = 0; } int main() { int n, a, r = 0, maxn = 0; int monety[NOMINALY]; zeruj(monety, NOMINALY); cin>>n; for (int i = 0; i < n; i++) { cin>>a; monety[a]++; } for (int i = 0; i < NOMINALY; i++) { monety[i] += r; if (monety[i] > 0) maxn = i; r = monety[i] / 2; monety[i] %= 2; } cout<<maxn<<"\n"; 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 | #include <iostream> #define NOMINALY 202000 using namespace std; void zeruj(int a[], int n) { for (int i = 0; i < n; i++) a[i] = 0; } int main() { int n, a, r = 0, maxn = 0; int monety[NOMINALY]; zeruj(monety, NOMINALY); cin>>n; for (int i = 0; i < n; i++) { cin>>a; monety[a]++; } for (int i = 0; i < NOMINALY; i++) { monety[i] += r; if (monety[i] > 0) maxn = i; r = monety[i] / 2; monety[i] %= 2; } cout<<maxn<<"\n"; return 0; } |