#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n; ll coins[202000]; int main() { cin >> n; ll max_a = 0; for (int i = 0; i < n; i++) { ll a; cin >> a; coins[a]++; max_a = max(max_a, a); } // cout << max_a << "\n"; ll ans = 0; for (int i = 0; (i <= max_a) || (coins[i] != 0); i++) { // cout << i << " " << coins[i] << "\n"; if (coins[i] != 0) { ans = i; } coins[i + 1] += coins[i] / 2; } cout << ans << "\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 34 | #include<bits/stdc++.h> using namespace std; typedef long long ll; ll n; ll coins[202000]; int main() { cin >> n; ll max_a = 0; for (int i = 0; i < n; i++) { ll a; cin >> a; coins[a]++; max_a = max(max_a, a); } // cout << max_a << "\n"; ll ans = 0; for (int i = 0; (i <= max_a) || (coins[i] != 0); i++) { // cout << i << " " << coins[i] << "\n"; if (coins[i] != 0) { ans = i; } coins[i + 1] += coins[i] / 2; } cout << ans << "\n"; return 0; } |