[Official] Contest 4 Hints

bro its getting terminated even before reading the input in the
CODEBLOCKS ide
may be there’s some issues with reading array
logic seems nice and usual …
nice understanding…

try using single variable v and circulate it everywhere and increment
instead of using x,x,z

My Understanding of EURON
a penny advice…
consider the eg Array : 3 9 2 6 4 5 7 1 21 8
(1st calculate answer directly by reading in mind each ele of array one by one)
partition it recursively into two halves
finally we will get individual elements …

The magic starts now(interval reached, film start)!!
now start merging this ele from left to right,
and each time you ,merge keep in mind ele in the left need to smaller than ele in the right…
else the no of terms on left which are less then no of ele on right adds to the required ans…
which you can initially set to 0.

*again i am not an expert *
just sharing my wisdom

can we solve STRSUB with window sliding techniqe?
i am not getting right ans,
can anyone help plz?
here my code

I have implemented LOWSUM with the 5th hint as well (because it gives TLE otherwise in Python for NLOGN search) and now it gives me WA. Can anyone help me to figure out any test case which I might be missing?

https://www.codechef.com/viewsolution/38654552

Can anyone Tell me what is wrong with my code . I am getting Wrong answer here.

ASHIGIFT:

#include<bits/stdc++.h>
using namespace std;
bool check(long long int n,long long int x[],long long int y[],long long int c[],long long int d[],long long int e[],long long int p,long long int b)
{
long long int prev = 0;
bool flag = true;
for (int i=0;i<p;i++)
{
long long int j;
for (j= prev;c[j]<=x[i] && j<b;j++)
{
if (n >= d[j])
n+=e[j];
}
prev = j;
if (n >= y[i])
n-=y[i];
else
{
flag = false;
break;
}
}
return flag;
}
long long int total(long long int ss,long long int se,long long int x[],long long int y[],long long int c[],long long int d[],long long int e[],long long int p,long long int b)
{
if (ss < se)
{
long long int mid = ss + (se - ss)/2;
if (check(mid,x,y,c,d,e,p,b))
total(ss,mid,x,y,c,d,e,p,b);
else
total(mid+1,se,x,y,c,d,e,p,b);
}
else if (ss == se)
{
if (check(ss,x,y,c,d,e,p,b))
return ss;
else
return
ss+1;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,p,b,sum = 0;
cin>>n>>p;
long long int x[p],y[p];
for (int i=0;i<p;i++)
{
cin>>x[i]>>y[i];
sum+=y[i];
}
cin>>b;
long long int c[b],d[b],e[b];
for (long long int i=0;i<b;i++)
cin>>c[i]>>d[i]>>e[i];

    cout<<total(1,sum,x,y,c,d,e,p,b)+1<<endl;
}

}

can anyone tell me what’s wrong with my code for the question STACKS
here’s the link to my solution CodeChef: Practical coding for everyone

Hi @helvetic4, Your B.S function is wrong also when you are passing the vector to function it’s making a new copy of vector, which will eventually cause TLE even if we fix the BS, so we have to pass it by reference

vector < int > &a

I have fixed everything and got AC using your code please check it here, in BS there was just one mistake you have to return low not high.
Reason: Link for Reason why low not high
AC Solution: Link

1 Like

my vector solution is also giving tle despite using binary search. i can’t understand where i am going wrong.
STACKS
#include
#include
using namespace std;
long long int search(vector stacks, long long int ini, long long int end, long long int temp)
{
long long int j;
if(((ini+end)/2)==end || ((ini+end)/2)==ini)
{
if(stacks[ini]>temp)
return(ini);

    else
    return(end);
}
/*else if(ini==end)
{
    return(end);
}*/
else
{
    j=(ini+end)/2;
    if(stacks[j]>temp)
    {
     return(search(stacks, ini, j, temp));
    }
    else
    {
        return(search(stacks, j, end, temp));
    }
}

}

int main() {
long long int t, n, temp, count, i, start, end, j;
cin>>t;
while(t–)
{
cin>>n;
vector stacks = {};
cin>>temp;
stacks.push_back(temp);
count=0;
for(i=1;i<n; i++)
{
cin>>temp;
if(stacks[count]>temp)
{
j = search(stacks, 0, count, temp);
stacks[j]=temp;
}
else
{
stacks.push_back(temp);
count++;
}
}
cout<<count+1<<" “;
for(i=0; i<=count; i++)
{
cout<<stacks[i]<<” ";
}
cout<<endl;
}
return 0;
}

ur binary search is wrong u r initialising low and high in function but u have to pass it.

in the problem EURON its clearly mentioned that its a set of numbers , things should be more clear , i did my first solution with set using upper bound then had to go back to traditional merge sort process for the correct ans to deal with duplicates ,

tell me one thing brother Q is just the number of Query , so how you can be sure that one of the Qith value wont be so large , how you so sure about that !len( Q) can be 10000 but how Q[i] must be with in 10000 explain that please , i am not getting that !

Thankyou

Problem link:- CodeChef: Practical coding for everyone
My Solution:- CodeChef: Practical coding for everyone
Please anyone tell me why my solution is giving TLE . According to me it should take O(b+c). Do tell if any correction can be made.

Please share the link to the LOWSUM solution video if there is any, I am facing difficulties to solve it.

My code is shows time limit exceed. I have implemented binary search but still it shows so.
Someone plz tell my why.
https://www.codechef.com/viewsolution/44078183

I am trying to solve TRANSACT problem. Below is my solution.
https://www.codechef.com/viewsolution/45975824

But I think there is something i am missing or have not understood the question properly. I checked the comments but i couldn’t find it relevant to my solution.

Can someone please check to see what is solution missing.

in the euron problem . I have been trying to solve that problem usinng staks and i have quite succeded in it but i don’t know why my Soln is geetibg wrong answere while it is running on alll given test cases can any one help me here is the link to my code
https://www.codechef.com/viewsolution/47878583

Consider the test input:

4
5 8 0 3

https://www.codechef.com/viewsolution/58872333

I have copy pasted your solution and submitted and it is giving wrong answer