This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
const int N = 2e3 + 10 , inf = 1e9;
int n , a[N];
void init(int nn , vector <int> vec)
{
n = nn;
for(int i = 0 ; i < n ; i++)
a[i] = vec[i];
}
int Solve(int l , int r , int d , int val)
{
if(l > r)
return 0;
int mn = inf;
int pos_mx = l;
for(int i = l ; i <= r ; i++)
{
mn = min(mn , a[i]);
if(a[i] > a[pos_mx])
pos_mx = i;
}
if(mn > val)
return 0;
int res = max(1 , Solve(l , pos_mx - 1 , d , a[pos_mx] - d) + Solve(pos_mx + 1 , r , d , a[pos_mx] - d));
return res;
}
int max_towers(int l , int r , int d)
{
return Solve(l , r , d , inf);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |