Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
import sys

def min_refills(d, m, n, st, f):
     if d >= m:
          return 0
     if m == 0:
          return -1
     s = round(d/m, 3)
     si = int(d/m)
     sm = round(s - si, 3)
     n = len(st)
     y, i, r = 0, 0, 0
     j = -1
     o = 1
     f = "true"
     while(f == "true"):
          i = i +1
          j = j + 1
          x = int(st[i])- int(st[j])
          if (x == 1 and s == d and m ==1):
               r = d-1
               return r
          if ((sm == 0.000) and(x<= m) and (d-int(st[n-1]) <= m)):
               r = int(s-1)
               return r
          if((x<= m) and (d-int(st[n-1]) <= m)):
               r = int(s)
               if i > (n-2):
                    f = "false"
                    return r
          elif((x > m)or (d-int(st[n-1]) >m) or (s < n )):
               f = "false"
               r = -1
               return r


if __name__ == '__main__':
    d = int(input())
    m = int(input())
    n = int(input())
    f = "true"
    st =  sys.stdin.read().split()
    print(min_refills(d, m, n, st, f))


What I have tried:

i tried running it but i dont know where the mistake is
Posted
Updated 13-Jun-20 14:54pm
v2
Comments
Richard MacCutchan 14-Jun-20 4:15am    
The main mistake is that using all those single character variable names, and the lack of comments, makes it impossible to understand what the code is supposed to do.

1 solution

Don't want to be rude, but:
Quote:
i tried running it but i dont know where the mistake is

The basics when you ask for help is to tell what is supposed to do your code and what it does wrong.
Giving a sample input data along with actual and expected outputs is a good idea too.
Asking questions is a skill[^]
Some guidelines for posting questions in the forums[^]
 
Share this answer
 
Comments
[no name] 25-Jun-20 9:19am    
I hate votes below 4 without comments, so have a 5 for balance.
Patrice T 25-Jun-20 9:31am    
Thank you again :)

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