【codeforces 546A】Soldier and Bananas
来源:互联网 发布:mysql explain type 编辑:程序博客网 时间:2024/06/05 02:04
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;}
- CodeForces 546A Soldier and Bananas
- Soldier and Bananas( CodeForces - 546A)
- CodeForces-546A-Soldier and Bananas
- 【CodeForces】[546A]Soldier and Bananas
- 【codeforces 546A】Soldier and Bananas
- Problem--546A--Codeforces--Soldier and Bananas
- codeforces 546A Soldier and Bananas
- CodeForces 546 A - Soldier and Bananas(模拟求和)
- codeforces 546A(Soldier and Bananas) Java
- A. Soldier and Bananas
- CF 546A Soldier and Bananas
- CF 546A-Soldier and Bananas
- A. Soldier and Bananas(CF546) Codeforces Round #304 (Div. 2)
- Codeforces刷题之路——546A Soldier and Bananas
- Codeforces546A:Soldier and Bananas
- Coderforces Soldier and Bananas
- #codeforces 546C# Soldier and Cards (模拟)
- CodeForces 546D Soldier and Number Game
- mvc的扩展3(composer的加载)
- 高性能 TCP/UDP/HTTP 通信框架 HP-Socket v4.1.2
- Windows环境下创建MySQL主从复制
- Struts2框架篇
- android_17_AndroidTestCase单元测试
- 【codeforces 546A】Soldier and Bananas
- android httpClient 支持HTTPS的处理方式
- 《项目管理利器Maven》学习(二):手动创建第一个Maven案例maven01
- MXnet实战心得---值得拥有
- 接口的作用和使用原则
- php基础
- mysql数据库中命令行下常用命令的操作(增、删、改、查)和数据类型
- jQuery EasyUI 1.2.4 API 中文文档(完整)目录
- Flutter进阶—质感设计之弹出菜单