Radeen10-_

codeforces mafia game

Jul 2nd, 2021 (edited)
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def satisfyeverybody(k,rounds):
  2.     #we play k rounds, then the person i can play i rounds.Then he can supervise k-i(rounds)
  3.     #total supervisor position sum(k-rounds[i]) over all i
  4.     supervisors = sum(map(lambda x: k - x, rounds))
  5.     return supervisors >= k
  6.  
  7. def minimum_rounds():
  8.     n=int(input())
  9.     rounds=list(map(int,input().strip().split()))
  10.  
  11.     if len(rounds)<=1:
  12.         return 0
  13.     lower_bound=0
  14.     upper_bound=sum(rounds)
  15.     answer=sum(rounds)
  16.     while lower_bound<=upper_bound:
  17.         mid=(lower_bound+upper_bound)//2
  18.         if (satisfyeverybody(mid,rounds)):
  19.             answer=mid
  20.             upper_bound=mid-1
  21.         else:
  22.             lower_bound=mid+1
  23.     return answer
  24.  
  25. print(minimumMafiaRounds())
  26.  
Add Comment
Please, Sign In to add comment