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
Input3 17 4Output13
题意:
士兵去买香蕉,买的第一根香蕉的价格为k,第i根的价格为i*k。给定士兵带的钱和需要买的香蕉数目,求士兵要借多少钱,如果不用借钱,则输出0.(由于没有判断输出0的条件WA了一发..冤枉啊!!!!!)
虽然是一道水题,但还是发出来劝解各位小伙伴和自己一定要认真读题,千万不要冤WA。
还是附AC代码:
#include<iostream>
using namespace std; int a[]; int main(){
int k,n,w,sum=;
cin>>k>>n>>w;
for(int i=;i<=w;i++){
a[i]=i*k;
sum+=a[i];
}
if(sum-n>)//!!!!!!
cout<<sum-n<<endl;
else
cout<<""<<endl;
return ;
}
最新文章
- C#委托和事件
- MATLAB 文件对话框之图片格式转换
- C语言修炼-第2天
- hdu 2018 母牛的故事
- Drupal8开发教程:认识.info.yml文件
- 关于Failed to convert property value of type [org.quartz.impl.StdScheduler] to required type [org.springframework.scheduling.quartz.SchedulerFactoryBean
- IOS8开发之实现App消息推送
- ASP.NET常用导出Excel方法汇总
- c++之 数组
- [Echarts]用Echarts绘制饼状图
- 1687: [Usaco2005 Open]Navigating the City 城市交通
- HTML解析器BeautifulSoup
- 边看MHA源码边学Perl语言之一开篇
- [ACdream]小晴天老师系列——竖式乘
- python读写word、excel、csv、json文件
- 01——Solr学习之全文检索服务系统的基础认识
- Partition--使用分区切换来增加修改列的自增属性
- windows上apache是线程处理请求,linux上apache是进程处理请求
- WPF中使用WindowChrome美化窗口过程中的一个小问题
- August 01st 2017 Week 31st Tuesday