A - Soldier and Bananas

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

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.

 

Sample Input

Input
3 17 4
Output
13

 

题意:

士兵去买香蕉,买的第一根香蕉的价格为k,第i根的价格为i*k。给定士兵带的钱和需要买的香蕉数目,求士兵要借多少钱,如果不用借钱,则输出0.(由于没有判断输出0的条件WA了一发..冤枉啊!!!!!)

 

虽然是一道水题,但还是发出来劝解各位小伙伴和自己一定要认真读题,千万不要冤WA。

 

还是附AC代码:

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int a[1001];
 5 
 6 int main(){
 7      int k,n,w,sum=0;
 8      cin>>k>>n>>w;
 9     for(int i=1;i<=w;i++){
10         a[i]=i*k;
11         sum+=a[i];
12     }
13     if(sum-n>0)//!!!!!! 
14     cout<<sum-n<<endl;
15     else
16     cout<<"0"<<endl;
17     return 0;
18 } 

 

posted @ 2016-07-27 16:30  Kiven#5197  阅读(328)  评论(0编辑  收藏  举报