CodeForces 546A-Soldier and Bananas

时间:2023-03-09 06:33:04
CodeForces 546A-Soldier and Bananas

题意:

  有n dollar,the first banana cost  k dollars,第i个就需cost k*i,问买w个bananas是否需要借钱;借钱需要多少?

分析:首先计算w个bananas需要多少money,在与n比较。


代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 int main()
{
int k, w;
long long n; while(scanf("%d%lld%d", &k, &n, &w)==)
{
int i;
LL tot = ;
for(i = ; i <= w; i++ )
tot += i*k; //计算w个bananas所需的money
if(n >= tot)
printf("0\n");
else
printf("%lld\n", tot - n); //比较总需费与n的大小,最后输出它们的差值
} return ;
}