SLUSH - EDITORIAL

thanks for helping :smile:

i corrected the errors but still the updated solution gives a TLE :- CodeChef: Practical coding for everyone
even after removing the erase part of map and simply just iterating over the map gave TLE : CodeChef: Practical coding for everyone

thanks in advance:smiley:

Most of the people here are talking about why they are getting a WA. The link below is my solution which has been accepted. It has detailed comments about everything which is happening in the code. You all can refer to my code and check your mistake.
Hope this helps. :slightly_smiling_face:
Lang: C++

Link to detailed solution: CodeChef: Practical coding for everyone

1 Like

I am getting TLE in this solution. I tried removing loop to see which one of them gave the error but I failed.
It would be really helpful if somebody could point out the mistake.
https://www.codechef.com/viewsolution/24942568

Encountered the same problem but after the contest
Saw a solution with String Builder class and it got accepted with old Reader Class as well
https://www.codechef.com/viewsolution/24941683

In every array indexing done from o to m-1 but u call can_sell[m] which doesn’t exist that’s why u r getting error

CHeck line 26: i have done from 1 to m only
for(int i=1;i<=m;i++){
cin>>can_sell[i];
}

You declare size 26 that means you can can index from 0 to 25 but you access 26th index read basics about array

please help:
(CodeChef: Practical coding for everyone)
applied the same logic as given in editorial.
not able to find why my soln is getting WA.

http://webdevforum.herokuapp.com/singlePost/5d11e4ce922f26001705c45e

Here is one good solution

Did anyone solve it in python 3. I implemented the similar logic but getting NZEC error

the following is my code
#include
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int av[m];
for(int i=0;i<m;++i)
cin>>av[i];
int d,f,b;
long long int cost = 0;
int fin[n];
for(int i=0;i<n;++i) fin[i] = -1;
for(int i=0;i<n;++i)
{
cin>>d>>f>>b;
if(av[d-1]>0 && f>b){
cost+=f;
fin[i] = d;
av[d-1]–;
}
else
cost+=b;
// cout<<cost<<"\n";
}
int curr = 0;
for(int i=0;i<n;++i)
{
if(fin[i] == -1){
while(av[curr]<=0)
{
curr++;
}
fin[i] = av[curr];
}
}
cout<<cost<<"\n";
for(int i=0;i<n;++i)
cout<<fin[i]<<" “;
cout<<”\n";
}
return 0;
}

I am getting wrong answer but it is a proper implementation of the explanation(I hope so).
Please help.

you need to make some changes to your if statement here :

 if(fin[i] == -1)
 {
     while(av[curr]<=0)
     { 
         curr++;
     }
     fin[i] = curr+1;
     av[curr]--;
 }

Also you might need to change your data types from int to long int at desired positions.
You can have a look at your code in action here: CodeChef: Practical coding for everyone

Used a similar logic as that of editorial , still getting WA .
Can someone please check the code?
https://www.codechef.com/viewsolution/24956087
thanks in advance!

Tried to code it as per the explanation , but i am getting WA for this. Please help.
Thank you very much.
https://www.codechef.com/viewsolution/24962878

Well, Without that, we can have two type of drinks, one where drinking the favorite drink is beneficial (F > B), and one where favorite drink cause loss (F < B). (We can treat drinks with F = B at the end, it doesn’t matter anyway.)

There can be some solution based on priorityQueue sorting drinks in descending order of |F-B| on basis of which we can make choices whether we can satisfy this constraint or not. Greedy should work.

What is the error in this?

#include <bits/stdc++.h>
using namespace std;
struct s
{ int d,f,b,ch,idx; };
bool compf(struct s a, struct s b)
{ return a.f > b.f; }
bool compb(struct s a, struct s b)
{ return a.b> b.b; }
bool compx(struct s a, struct s b)
{ return a.idx <b.idx; }
int main()
{
int t;cin>>t;while(t–)
{
int n,m; cin>>n>>m;struct s st[1000000];
int c[m+1],sum=0;
for(int i=1;i<=m;i++) { cin>>c[i];}//cout<<c[i]<<" “; }cout<<endl;
for(int i=0;i<n;i++)
{ cin>>st[i].d>>st[i].f>>st[i].b;st[i].ch=-1;
st[i].idx=i;
}
// sort(st,st+n,compf);
for(int i=0;i<n;i++)
{
if(c[st[i].d]>0)
{sum+=st[i].f;
c[st[i].d]–;
st[i].ch=st[i].d;}
//cout<<st[i].d<<” “<<c[st[i].d]<<endl;
}
//for(int i=1;i<=m;i++) cout<<c[i]<<” "; cout<<endl;

// sort(st,st+n,compb);
for(int i=0;i<n;i++)
{
if(st[i].ch==-1)
{
int j=1;// cout<<j<<" “;
while(st[i].ch==-1)
{
if(c[j]>0 &&j<=m)
{
c[j]–;
st[i].ch=j;
sum+=st[i].b; break;
}
j++;
}
}
}
cout<<sum<<endl;
sort(st,st+n,compx);
for(int i=0;i<n;i++)
{//cout<<“h”;
cout<<st[i].ch<<” ";
}
cout<<endl;
}
return 0;
}

can you also give the test cases?

Using a long long int as index for an array sometimes results in seg faults
if(c[d]>0)
is probably giving you that error

1 Like

Can anyone explain me this ? . In order to not miss favorite slush of persons coming later would be to wait until the end in order to assign a person slush whose favorite slush is not available . So that way we maximize the profit right . So the thing that got me confused is . If we are waiting till end can we not wait till a person comes whose Fi is more among all those with same favourite slush . Like in this test case .

1
5 3
1 2 3
2 6 3
2 10 7
2 50 3
1 10 5
1 7 4

can we not make people wait until the third person with Fi value of 50 comes so , we sell him the slush and sell second person with Fi 10 . I’m confused with waiting and assigning them the slush

My approach is same as Editorial, but still I am getting wrong ans. Please help me out !!
Here is the link to solution link