September lunchtime division 2 chef and football match

question : https://www.codechef.com/LTIME76B/problems/WATCHFB
my answer: https://ideone.com/66JfAn
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?:sweat_smile:

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
:slight_smile:

1 Like

Thanks Dev for your reply.
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 ?
ss
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 ?
Thanks for your kind help.

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…???
you can google or some other guys can help you…

Yes I gone through your solution and understood the correct tracking of scores.May I know how many problems you could solve in that contest ? Btw, I couldn’t get the first few lines of your code :sweat_smile:

This was my first Division 1 contest …and i have just solved first 2 problems of div 1 in the contest.