546A. Soldier and Bananas

546A. Soldier and Bananas

546A. Soldier and Bananas

  • time limit per test1 second
  • memory limit per test256 megabytes
  • inputstandard input
  • outputstandard output

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).

一名士兵想在商店里买香蕉。他必须为第一根香蕉支付k美元,为第二根香蕉支付2k美元,依此类推(换句话说,他必须为第i根香蕉支付i·k美元)。

He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?

他有n美元。为了买香蕉,他必须向他的朋友士兵借多少美元?

Input

The first line contains three positive integers k, n, w (1  ≤  k, w  ≤  1000, 0 ≤ n ≤ 109^9), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.

第一行包含三个正整数k, N w (1  ≤  k, w  ≤  1000, 0 ≤ n ≤ 109^9),第一根香蕉的价格,士兵最初拥有的美元数量和他想要的香蕉数量。

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.

输出一个整数——士兵必须向朋友借的美元金额。如果他不需要借钱,输出0。

Examples
inputCopy

3 17 4

outputCopy

13

Solution
Code
#include <iostream>
using namespace std;
//
int main(){
    int k = 0;
    int n = 0;
    int w = 0;
    cin >> k >> n >> w;
    int sum = k * ((1 + w)* w / 2);
    if(sum <= n){
        cout << "0" << endl;
    }else{
        cout << sum - n << endl;
    }
}
CodeForces 文章被收录于专栏

https://codeforces.ml/

全部评论

相关推荐

10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务