 # November Cook - Off Discussion

Created a common thread so we all can discuss our doubts, rather than to have multiple threads to answer individual doubts.
Hence prevent less spam.

Feel free to share your doubts regarding any question or fault in your approach.
Thank you 3 Likes

What’s wrong with this approach for The Biggest Restaurant?

1. I am sorting both x and h
2. To get the maximum ans i am making h sequence something like this in alternative fashion:
if h = {1,2,3,4} -> nh = {1,4,3,2}
h = {1,2,3,4,5} -> nh = {1,5,3,4,2}
h = {1,2,3,4,5,6} -> nh = {1,6,3,4,5,2}
and so on i formed a sequeunce by this logic.
3. Then i just calculated area of triangle and square of two consecutive points while traversing.

My Solution - https://www.codechef.com/viewsolution/27936807

Thank you I have doubt in the DIET proble.
my code is throwing SIGSEGV problem.
#include <stdio.h>

int main() {
int t,n,i,j=0,temp=0;
long int k,arr[n];
scanf("%d",&t);

for(int v=0;v<t;v++){

``````scanf("%d %ld",&n,&k);
for(i=0;i<n;i++){
scanf("%ld",&arr[i]);}
for(i=0;i<n;i++){
if(arr[i]>=k){
temp=arr[i]-k;
if(i<n-1)
arr[i+1]+=temp;
}
else{
printf("NO %d\n",i+1);
j++;
break;
}

}
if(j==0)
printf("YES\n");
``````

}
return 0;
}

Hi all,
I tried solving ROBOTS, https://ideone.com/2iENcd
Can somebody tell me where did I go wrong

bcz u declare an array of size n which is undefined.

2 Likes

You have declared the array of size ‘n’ before taking value of ‘n’ from input.

Does my code have logical error or precision error for ROBOTS?

``````#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int T,N,Q,L,R,i;
cin>>T;
string str;
while(T--)
{
cin>>N>>Q;
cin>>str;
int x=0,y=0;
double s=sqrt(3);

int X[N+1],Y[N+1];
X=0;
Y=0;
for(i=0;i<N;i++)
{
switch(str[i])
{
case '0': x+=2;break;
case '1': x+=1;y+=1;break;
case '2': x-=1;y+=1;break;
case '3': x-=2;break;
case '4': x-=1;y-=1;break;
case '5': x+=1;y-=1;break;
}
// printf("%.8f %.8f\n",x,y);
X[i+1]=x;
Y[i+1]=y;
}
while(Q--)
{
cin>>L>>R;
x=X[R]-X[L-1];
y=Y[R]-Y[L-1];
double a,b;
a=x*0.5;
b=(y*sqrt(3))/2;
printf("%.8f %.8f\n",a,b);
}
}
}``````

https://www.codechef.com/viewsolution/27939315
ROBOTS problem
why is this giving WA while it works on all my custom testcases?
I dont see where the problem could’ve been

This only works when the differences X_{i} -X_{i-1} = 1.

1 Like

Could someone help with me with my code for ROBOTS , I used a segment tree but got WA:
https://www.codechef.com/viewsolution/27938640

ohh yeah, you are correct.

The problem statement was too long and too confusing

1 Like

1
5
0 1
2 2
3 3
4 4
5 5
corr. ans. 34
Corr. sequence 2 5 3 4 1
I think X also plays role in deciding h.
P.S. - I didn’t get AC too. 2 Likes

I am Not Getting The idea for Biggest Restaurant. Can someone explain the logic?

Apply trapezium area formula not triangle + rectangle or square
And after making right arrangement for height we need to find the greatest difference of heights that is points on x axis. Therefore the maximum sum(sum of columns) will be multiplied to maximum difference of two consecutive points .

And the arrangement of columns can be in this way for maximum
{2,4,6,5,3,1}

1 Like

Use the area of trapezium for this problem

1 Like

I think we can use Shoelace Formula to calculate area of Polygon.

Thanks For The Help.

could u please elaborate how u come up with such sequnce and what is the sequence?? it will be of great help

That means each element of sorted array of sum of adjacent heights and sorted array of difference of adjacent heights will be multiplied and added to give answer?