Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are N problems in this contest; each problem has a unique problem code between 1 and N inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems whose problem codes are divisible by A but not divisible by B, and Chef should solve the problems whose problem codes are divisible by B but not divisible by A (they decided to not solve the problems whose codes are divisible by both A and B).

To win, it is necessary to solve at least K problems. You have to tell Appy whether they are going to win or lose.
1≤T≤15
1≤K≤N≤106
1≤A,B≤103

For each test case, print a single line containing the string "Win" if they can solve at least K problems or "Lose" otherwise (without quotes).


sample input .....................
1
6 2 3 3

What I have tried:

Python
t= int(input())
for _ in range(t):
    n , a , b , k = input().split()
    p = int(a)*int(b)
    if p<=int(n):
        m = p 
        
    elif p>int(n):
        m = int(n) 
        
    arr_a = []
    i = 1
    while int(a)*i<m :
        arr_a.append(int(a)*i)
        i+=1 
    
    arr_b = []
    i=1
    while int(b)*i<m :
        arr_b.append(int(b)*i)
        i+=1 
    
    if sum(arr_a)>=int(k) and sum(arr_b)>=int(k):
        print("Win")
    else:
        print("Lose")

this code is running only for the sample input but not running for any other input and showing the wrong answer as an error when I'm submitting it in codechef

Link: Contest Page | CodeChef[^] (not visible for non registered user)
Posted
Updated 7-May-21 0:01am
v6
Comments
Patrice T 6-May-21 6:41am    
What do you mean by "wrong" ?
Muskan Verma 2021 6-May-21 7:11am    
this code is running only for the sample input but not running for any other input and showing the wrong answer as an error when I'm submitting it in codechef
Patrice T 6-May-21 7:38am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
CPallini 6-May-21 8:59am    
Do you have an exact description of the problem (the posted one is a bit confused)?
Maybe you have a link to the original one.
Muskan Verma 2021 6-May-21 11:20am    
yes sir.
URL is...
https://www.codechef.com/LRNDSA05/problems/HMAPPY2

Quote:
this code is running only for the sample input but not running for any other input and showing the wrong answer as an error when I'm submitting it in codechef

Time to learn how to debug your code.
Get some sample dataset, or make your own, then launch the debugger to see how your code handle the data.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

27.3. pdb — The Python Debugger — Python 3.6.1 documentation[^]
Debugging in Python | Python Conquers The Universe[^]
pdb – Interactive Debugger - Python Module of the Week[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
I think that both the approach and the implementation of your program are flawed.
The approach cannot work (I believe) because your code is going to collect to many items in the 'arrays' (anyway iteration is not an option when such big inputs are allowed).
The implementation is flawed as well, because your code is not summing up Appy and Chef scores.
Hint: consider the Least Common Multiple[^] concept.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900