比如说我想给一些员工一些钱。每个员工必须得到 $a 和 $b 之间的美元。第一个员工得到 $a,每个后续员工比上一个员工多得到 $k,直到该金额超过 $b,在这种情况下,该员工得到 $b,之后每个后续员工得到 $k,直到该金额低于$a 在这种情况下,员工将获得 $a,并且所有 n 名员工的循环都将继续。我想将总支出退还给所有员工
到目前为止我所拥有的:
#!/bin/python3
import os
import sys
def payEmp(n, a, b, k):
totalPayOut = 0
currentPay = 0
increase = True
for i in range(n):
if increase == True:
if currentPay < a:
currentPay += a
else:
currentPay += k
if currentPay >= b:
totalPayOut += b
increase = False
else:
totalPayOut += currentPay
else:
currentPay -= k
if currentPay <= a:
totalPayOut += a
increase = True
else:
totalPayOut += currentPay
return totalPayOut
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
nabk = input().split()
n = int(nabk[0])
a = int(nabk[1])
b = int(nabk[2])
k = int(nabk[3])
result = payEmp(n, a, b, k)
fptr.write(str(result) + '\n')
fptr.close()