A Soldier wants to Buy w bananas in the shop. He has to Pay K dollars for the first banana, 2 k dollars for the second one and so on (in other words, he have to Pay i · k dollars for The i -th banana).
He has n dollars. How many dollars does he has to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k,? N,? w (1?? ≤?? k,? w?? ≤?? 0?≤, huh? N. ≤?109), the cost of the first banana, initial number of dollars the soldier have and number of bananas He wants.
Output
Output one integer-the amount of dollars, the soldier must borrow from his friend. If He doesn ' t has to borrow money, output 0.
Sample Test (s) input
3 17 4
Output
13
Test instructions
To buy a W banana, the first k yuan, the second 2k, the first I i*k, now has n yuan, also how many yuan
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include < vector> #include <math.h> #include <bitset> #include <list> #include <algorithm> #include <climits>using namespace std; #define Lson 2*i#define Rson 2*i+1#define LS l,mid,lson#define RS mid+1,r,rson#define Up (I,x,y) for (i=x;i<=y;i++) #define DOWN (i,x,y) for (i=x;i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define GCD (A, B) __gcd (A, b) #define LL long long#define N 5000005#define INF 0x3f3f3f3f#define EXP 1e-8#define Lowbit (x) (x&-x) const int mod = 1E9+7; LL N,k,w;int Main () {int i; LL sum = 0; scanf ("%i64d%i64d%i64d", &k,&n,&w); for (i = 1;i<=w;i++) sum +=i*k; if (n>=sum) printf ("0\n"); else printf ("%i64d\n", sum-n); return 0;}
Codeforces546a:soldier and Bananas