-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBucket.cpp
52 lines (48 loc) · 1.21 KB
/
Bucket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int ans=0,n=0;
void func(int currentElem,vector<int>& height,int ct,int element)
{
cout<<"current index : "<<currentElem<<" element : "<<element<<" ans : "<<ans<<"\n";
if(currentElem>=n-1)
{ if(ans<ct*element)
{
ans=ct*element;
}
cout<<"current index : "<<currentElem<<" element : "<<element<<" ans : "<<ans<<"\n";
return;
}
else if(height[currentElem]>=element)
{
func(currentElem+1,height,ct+1,element);
func(currentElem+1,height,0,height[currentElem]);
}
else
{
if(ans<ct*element)
{
ans=ct*element;
}
cout<<"current index : "<<currentElem<<" element : "<<element<<" ans : "<<ans<<"\n";
return;
}
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int x=0;
cin>>n;
vector<int> height;
for(int i=0;i<n;i++)
{
cin>>x;
height.push_back(x);
}
func(0,height,0,height[0]);
cout<<ans<<"\n";
return 0;
}