Submission
Status:
----------
Subtask/Task Score:
0/100
Score: 0
User: nate213121
Problemset: ประลอง
Language: cpp
Time: 0.002 second
Submitted On: 2026-09-05 14:49:52
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> columnHeights(n);
int maxHeight = 0;
for(int i = 0; i < n; i++)
{
cin >> columnHeights[i];
maxHeight = max(maxHeight, columnHeights[i]);
}
vector<vector<int>> grid(maxHeight + 1, vector<int>(n));
for(int col = 0; col < n; col++)
{
int currRow = maxHeight;
int height = columnHeights[col];
for(int x = 0; x < height + 1; x++)
{
grid[currRow][col] = 1;
currRow--;
}
}
/*for(int i = 0; i < maxHeight + 1; i++)
{
for(int j = 0; j < n; j++)
{
cout << grid[i][j];
}
cout << endl;
}*/
int total = 0;
for(int row = 0; row < maxHeight + 1; row++)
{
int col = 0;
while(col < n)
{
if(grid[row][col] == 1)
{
col++;
int airCount = 0;
while(col < n && grid[row][col] == 0)
{
airCount++;
col++;
}
if(col < n && grid[row][col] == 1)
{
total += airCount;
}
}
else
{
col++;
}
}
}
cout << total;
return 0;
}