[codeforces] A. Soldier and Bananas알고리즘(Python,Java)2019. 12. 7. 17:35
Table of Contents
반응형
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Using language : python3
def solution(userinput_list):
answer_sum = 0
for check in range(0,int(userinput_list[2])):
answer_sum += int(userinput_list[0]) * (check+1)
return answer_sum - int(userinput_list[1])
if __name__ == "__main__":
input1 = list(input().split(" "))
if solution(input1) <= 0 :
print("0")
else:
print(solution(input1))
반응형
'알고리즘(Python,Java)' 카테고리의 다른 글
[codeforces] A. HQ9+ (0) | 2019.12.26 |
---|---|
[codeforces] A. Twins (0) | 2019.12.23 |
[codeforces] Lucky Division (0) | 2019.11.29 |
[codeforces] Tram (0) | 2019.11.27 |
[codeforces] A. Chat room (0) | 2019.11.25 |
@IT grow. :: IT grow.
#IT #먹방 #전자기기 #일상
#개발 #일상