# September lunchtime division 2 chef and football match

question : https://www.codechef.com/LTIME76B/problems/WATCHFB
i am still getting wrong answer in these question why??

for first case
2 1 1
it is wrong

1 Like
``````#include <iostream>
using namespace std;
int main() {
int t, fav = 0;
cin >> t;
while (t--) {
int n;
cin >> n;
while (n--) {
int stat, a, b;
cin >> stat >> a >> b;
if (stat == 1) {	//for stat == 1
fav = a;
cout << "YES"<<endl;
}
if(stat==2) {	//for stat == 2
if (a != b) {	//for unequal
if (a < fav || b < fav) {	//one of them is less than current score of fav
cout << "YES"<<endl;
a > b ? fav = a : fav = b;
}
else {	//both are greater than fav
cout << "NO" << endl;
}
}		//for equal
else {
cout << "YES"<<endl;
fav = a;
}
}
}
}
}
``````

Can please anyone give me a hint why I am getting WA error?

can you please explain in detailâ€¦vipul747555

ok thank you i got the problem.

I havenâ€™t debug your code completely yet.
but the very first mistake, that i got, in your code is that you havenâ€™t initialized fav for each test caseâ€¦
Fix that and then again submit as a practiceâ€¦ then do let me knowâ€¦

Updated :
Now i have debugged your codeâ€¦
your code will fail in this test case :
1
4
2 0 1
1 3 1
1 4 7
2 5 8

Problem with your code : In third query : 1 4 7 you are just updating the value of fav â€¦you should keep track of other team score as wellâ€¦
Becoz in your code answer of 4th query will be wrong â€¦when both of them will be greater than previous favâ€¦answer may existâ€¦in this case answer is YES becoz 5 is less then previous other team score but greater than previos favâ€¦
You can refer my solution : https://www.codechef.com/viewsolution/26846032

1 Like

I couldnâ€™t understand the initialization of fav before each caseâ€¦
I alter the dev variable through the cases and make decision in each case based on the value stored in it.
Maybe I am missing something very basic. It would be great if you point to.
Thanks

@vishalg8454 Bro, check out the following test case:

``````1
6
1 1 3
2 2 3
2 3 5
2 5 6
2 8 8
2 9 10
``````

For `stat == 1` you assign 1st team goal â€śaâ€ť into fav [i.e, `fav = a`]
But you should assign maximum value to fav, I mean `fav = max(a, b)`

Here is your fixed (AC) solution

1 Like

@smile_forever Thanks, that really solved my problem. But I couldnâ€™t get why ? What I have assumed is that if the response starts with 1 the A corresponds to favorite team and B corresponds to other team. Isnâ€™t it ?
Or is it like that , â€śit just works!â€ť ?

1
4
2 0 1
1 3 1
1 4 7
2 5 8
Bro, this is what i have explained youâ€¦ in the third query ,what you was doingâ€¦just storing the 4 as favourite scoreâ€¦
and in next query ( 2 5 8 ) ,you are saying both of new scores are greater than 4 â€¦So, ans is NOâ€¦but here correct answer should be YESâ€¦because after 4, 7 ,score 5, 8 is a valid score and we can get 5 for favouriteâ€¦
Once,you fix that like smile_forever has doneâ€¦then in third query you are going to store 7 as fav (although which is not the favourite team score) and in next query when 5 is less then 7 you got correct answerâ€¦

@vishalg8454 You just tracking the maximum score, not the favorite team score.

Here is a solution which track both team score as well. May be it clear away confusion.

I also did the same, assigned goal a to fav team when q was 1. But I dont understand why do we have to take max(a, b) ?

1 Like

So I am assuming that `fav=max(a,b)` just makes the code work !
And I would like to mention that my solution behind this question was strictly based on the assumption that in " 1 A B" , A is the score of favorite team and B is score of other team. Also I still believe on my assumption. I have attached the ss of question. Please tell me if I am interpreting something wrong ?

I see that using the `fav=max(a,b)` works in the above given cases but couldnâ€™t get the solid reason behind that.

1 Like

@smile_forever
yes bro, I see that the question needs to be taken more deeply than I have taken. `max(a,b)` just solved the problem for the moment. Am i thinking correct ?

1 Like

Okh fine,donâ€™t fix like thatâ€¦
you can store both team score seperately as i have doneâ€¦
See my solution : https://www.codechef.com/viewsolution/26846032

@vishalg8454
Sounds good. Yep, now you thinking in the right way.

Anyway, you can solve this problem by assumption (by tracking maximum score) but you canâ€™t say that score hold chefâ€™s favorite team. Thatâ€™s why you should track both team score, that clear away confusion.

1 Like

Oh yes bro, I see that your solution just dealt with that flawlessy.

Btw I am amazed by the community ! This is my first interaction on codechef forum. Btw, I have just started on codechef. Solving questions from beginner even feels like moving mountains atm. I see you guys are quite ahead. I seriously feel I lack a good plan for doing all these. I read somewhere that solving ad-hocâ€™s first might help. Can you please give me some pointers ? That would be great help for me.
Thank you.

did you understand now the solution and problem with your approachâ€¦?
and I am also a beginnerâ€¦So, i donâ€™t thinkâ€¦i am right person to give you suggestionsâ€¦???