#include #include #include #include using namespace std; int main() { vector pyramid_blocks; int index = 0; for (int count_block = 1; count_block < 10000; count_block += 2) { int *blocks = new int[2]; if (count_block == 1) { blocks[0] = 1; blocks[1] = 1; } else { blocks[0] = pyramid_blocks[index - 1][0] + count_block; blocks[1] = count_block; } pyramid_blocks.push_back(blocks); index++; } int n; cin >> n; int blocks[101]; int count_all_block = 0; for (int i = 0; i < n; i++) { string count_block; cin >> count_block; blocks[i] = stoi(count_block); count_all_block += blocks[i]; } int pyramid_row_index = 0; for (int i = 0; i < pyramid_blocks.size(); i++) { if (pyramid_blocks[i][0] <= count_all_block) { pyramid_row_index = i; } else { break; } } int max_width = pyramid_blocks[pyramid_row_index][1]; int* pyramid_data = new int[max_width]; for (int i = 0; i < max_width; i++) { pyramid_data[i] = 0; } int count_row = 0; for (int y = pyramid_row_index; y >= 0; y--) { int* blocks = pyramid_blocks[y]; for (int x = 0; x < blocks[1]; x++) { pyramid_data[x + count_row]++; } count_row++; } for (int i = 0; i < min(max_width, n); i++) { count_all_block -= min(pyramid_data[i], blocks[i]); } cout << count_all_block << endl; return 0; }