We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
bool Ok(int32_t k) {
map M;
int32_t mask = 0;
for (int32_t i = 30; i >= k; i--) {
mask |= (1< vec;
for (map::iterator it = M.begin(); it != M.end(); ++it) {
vec.push_back(it->second);
}
sort(vec.begin(), vec.end());
if (vec.size() == 1) return false;
int32_t s = vec[0];
for (int32_t i = 1; i < vec.size(); i++) {
if (s < vec[i]) return false;
s += vec[i];
}
return true;
}
int32_t main() {
scanf("%d", &n);
for (int32_t i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
for (int32_t k = 30; k >= 0; k--) {
if (Ok(k)) {
printf("%d\n", k);
break;
}
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Manipulative Numbers
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
include
using namespace std;
const int32_t N = 101; int32_t A[N]; int32_t n;
bool Ok(int32_t k) { map M; int32_t mask = 0; for (int32_t i = 30; i >= k; i--) { mask |= (1< vec; for (map::iterator it = M.begin(); it != M.end(); ++it) { vec.push_back(it->second); } sort(vec.begin(), vec.end()); if (vec.size() == 1) return false; int32_t s = vec[0]; for (int32_t i = 1; i < vec.size(); i++) { if (s < vec[i]) return false; s += vec[i]; } return true; } int32_t main() { scanf("%d", &n); for (int32_t i = 0; i < n; i++) { scanf("%d", &A[i]); } for (int32_t k = 30; k >= 0; k--) { if (Ok(k)) { printf("%d\n", k); break; } } return 0; }