Below is my code, don't know where is the error!
#include <bits/stdc++.h>
using namespace std;
int maxp(vector<vector<int>>& garden)
{
int n = garden.size();
int m = garden[0].size();
vector<vector<int>> dp(n, vector<int>(m, 0));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (garden[i][j] == -1)
{
dp[i][j] = (i > 0) ? dp[i - 1][j] : 0;
}
else
{
if (i == 0)
{
dp[i][j] = 1;
}
else
{
dp[i][j] = max((i > 0) ? dp[i - 1][j] : 0, (i > 1) ? dp[i - 2][j] : 0) + 1;
}
}
}
}
int maxPlants = 0;
for (int j = 0; j < m; j++)
{
maxPlants = max(maxPlants, dp[n - 1][j]);
}
return maxPlants;
}
int minp(vector<vector<int>> &garden)
{
int n = garden.size();
int m = garden[0].size();
int count = 0;
for (int i = 0; i < n; i++)
{
bool planted = false;
for (int j = 0; j < m; j++)
{
if (garden[i][j] == 1 && (!planted || j == 0))
{
count++;
planted = true;
}
else
{
planted = false;
}
}
}
return count;
}
void tate()
{
int n, m;
cin >> n >> m;
vector<vector<int>> grid(n, vector<int>(m, 1));
int broke;
cin >> broke;
while (broke--)
{
int x, y;
cin >> x >> y;
grid[x][y] = -1;
}
int ans1 = maxp(grid);
int ans2 = minp(grid);
cout << ans1 << ' ' << ans2;
}
signed main()
{
int t = 1;
// cin >> t;
while (t--)
tate();
return 0;
}