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

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.

Examples
input
3 17 4
output
13

【题目链接】:http://codeforces.com/contest/546/problem/A

【题解】

就是w个数的等差数列的求和公式。
然后如果钱够的话输出的是0!!!!
否则输出差的绝对值就好.
细心。

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);

LL k,n,w;

int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    rel(k);rel(n);rel(w);
    LL temp1 = (k + w*k)*w/2;
    LL temp = n-temp1;
    if (temp <0)
        cout << abs(temp)<<endl;
    else
        puts("0");
    return 0;
}
posted @ 2017-10-04 18:45  AWCXV  阅读(203)  评论(0编辑  收藏  举报