Getting Wrong answer ?!?!

I believe my solution is correct , but dont't know why the site says that my answer is wrong , maybe you can help . Here goes the question :-
Problem 2: The Lead Game, (K Narayan Kumar, CMI)
The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient.
The game consists of several rounds and in each round both players obtain a score, based on how well they played. Once all the rounds have been played, the total score of each player is determined by adding up the scores in all the rounds and the player with the higher total score is declared the winner.
The Siruseri Sports Club organises an annual billiards game where the top two players of Siruseri play against each other. The Manager of Siruseri Sports Club decided to add his own twist to the game by changing the rules for determining the winner. In his version, at the end of each round the leader and her current lead are calculated. Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner.
Consider the following score sheet for a game with 5 rounds:
Round Player 1 Player 2

1 140 82
2 89 134
3 90 110
4 112 106
5 88 90
The total scores of both players, the leader and the lead after each round for this game is given below:
Round Player 1 Player 2 Leader Lead

1 140 82 Player 1 58
2 229 216 Player 1 13
3 319 326 Player 2 7
4 431 432 Player 2 1
5 519 522 Player 2 3
The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1) during the game.
Your task is to help the Manager find the winner and the winning lead. You may assume that the scores will be such that there will always be a single winner. That is, there are no ties.
Input format
The first line of the input will contain a single integer N (N ≤ 10000) indicating the number of rounds in the game. Lines 2,3,...,N+1 describe the scores of the two players in the N rounds. Line i+1 contains two integer Si and Ti, the scores of the Player 1 and 2 respectively, in round i. You may assume that 1 ≤ Si ≤ 1000 and 1 ≤ Ti ≤ 1000.
Output format
Your output must consist of a single line containing two integers W and L, where W is 1 or 2 and indicates the winner and L is the maximum lead attained by the winner.
Test Data
The range of values over which your program is to be tested is mentioned above.
In addition, 50% of the test cases will also satisfy N ≤ 1000.
Example
We now illustrate the input and output formats using the example described above.
Sample input:
5
140 82
89 134
90 110
112 106
88 90
Sample output:
1 58

And heres my solution to it :-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main(){
    int n,pof,pos,i,l=0,w;
    cin>>n;
    for (i=0;i<n;i++) {
        cin>>pof>>pos;
        if (pof>pos) {
           if (pof>pos) {if ((pof-pos)>l) {l=pof-pos;w=1;}}
           if (pof<pos) {if ((pos-pof)>l) {l=pos-pof;w=2;}}
        }
    }
    cout<<w<<" "<<l;
}

Can anybody Please help me out ?
Who says you're wrong and why? Just running the code with the sample input seems to give the sample output. I didn't read the exercise though; serious tl;dr going on here. Just be more specific in your question please.

[edit]
By the way, considering you're using signed integers, the outer if's are actually useless. Replacing lines 9 & 10 with:
1
2
if ((pof-pos)>l) {l=pof-pos;w=1;}
if ((pos-pof)>l) {l=pos-pof;w=2;}

will do just the same. If pof<pos, then the first will result to a negative number, which is always " < l".
Last edited on
Still , it is giving wrong answer (according to the site) !
Oh come on, at least give us SOME extra information. Why is it wrong? What website? What are they testing on? You're doing no effort to explain your situation. As far as I'm concerned, your code works for the example given.
Ok , URL of this problem is http://opc.iarcs.org.in/index.php/problems/LEAFEAT and its compiler is gnu based . It simply gives me "Wrong Answer" when i submit this , although it works perfectly in example !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main(){
    int n,pof,pos,i,l=0,w;
    cin>>n;
    for (i=0;i<n;i++) {
        cin>>pof>>pos;
        if (pof>pos) {  // Remove this if because it means player1 always wins
           if (pof>pos) {if ((pof-pos)>l) {l=pof-pos;w=1;}}
           if (pof<pos) {if ((pos-pof)>l) {l=pos-pof;w=2;}}
        }
    }
    cout<<w<<" "<<l;
}


The website will use other sample data. Your original code declares wrong winner for the following input data where I swapped the scores in line 2.

1
2
3
4
5
6
5
82 140
89 134
90 110
112 106
88 90



Last edited on
Yes Vin , you were correct , i understood my mistake and corrected it (it was really very childish !) , but still it is saying Wrong Answer !
Heres my corrected program :-
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
int main(){
    int n,pof,pos,i,l=0,w;
    cin>>n;
    for (i=0;i<n;i++) {
        cin>>pof>>pos;
           if (pof>pos) {if ((pof-pos)>l) {l=pof-pos;w=1;}}
           if (pof<pos) {if ((pos-pof)>l) {l=pos-pof;w=2;}}
    }
    cout<<w<<" "<<l;
}

Can you help me again ?
I'm not sure what the website wants exactly.

If it is testing your program with sample input for 5000 rounds (it says 50% of test cases will be N > 1000) it may need your program to read input from a file.

Maybe your program fails the CPU timelimit.
If I saw a program with a variable whose name was simply a lower case L, I would automatically count it wrong even if it was exactly like the judge-correct program besides the lower case L. Write code that is GNU: Good, Not Ugly!

As for your code, I fail to see quite how it solves the problem? Nevermind, you linked to entirely the wrong problem. Maybe that's it? You're submitting to the wrong problem?
Last edited on
Read the problem again.
Look at the example. See how the score is calculated an what you are doing.
After fully reading it, I do see the problem. Maggi, you're only judging a single round, instead of N rounds.
How come Gaminic ???
I was trying to judge 'n' rounds using the for loop at line 6 !
You're evaluating each round separately. The key phrase is here:
In his version, at the end of each round the leader and her current lead are calculated. Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner.

If the first round is 10-15 (p2->+5) and the second 8-10(p2->+2), the output should be p2->+7.

You have to sum up the scores, not evaluate round per round.
On this page is the test data used for the problem. It contains many sample inputs and the answer your program should give for each input.

http://www.iarcs.org.in/inoi/contests/allproblems.php
Oh , i got it , what i was doing was not what was asked at all !
Thankyou very much Gaminic & vin your link is very very very useful .
Thankyou all.
Topic archived. No new replies allowed.