Codeforces546A:Soldier and Bananas

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 test(s)

input

3 17 4

output

13


题意:
要买w个香蕉,第一个k元,第二个2k,第i个i*k,现在有n元,还需要多少元

#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;
}

时间: 2024-10-11 16:09:20

Codeforces546A:Soldier and Bananas的相关文章

水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

题目传送门 1 /* 2 水题:ans = (1+2+3+...+n) * k - n,开long long 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 typedef long long ll; 11 12 int main(void) //Codeforces Roun

CodeForces 546 A - Soldier and Bananas

题目链接:click here~~ [题目大意] 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 d

Soldier and Bananas

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给出第一个香蕉的价钱k,后买的第i个香蕉所需要的价钱就是i*k: 给出手上所有的钱,求出如果要买w个香蕉还少多少钱. 代码: 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int k,w,n, sum=0; 6 cin>>k>>n>

546A. Soldier and Bananas

  等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0) Java程序   import java.util.Scanner; public class A546 { static void run(){ Scanner in = new Scanner(System.in); int k =in.nextInt(); int n = in.nextInt(); int w = in.nextInt(); int count = 0; count = (1+

codeforces水题100道 第五题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas (math)

题目链接:http://www.codeforces.com/problemset/problem/546/A题意:一个人现在有n元,它买第i根香蕉需要i*k元,问他要买w根香蕉的话,需要问他的朋友借多少钱?C++代码: #include <iostream> using namespace std; int n, k, w; int main() { cin >> k >> n >> w; cout << max(0, w*(w+1)/2*k-

Codeforces Round #304 (Div. 2) -----CF546

A. Soldier and Bananas 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 dol

【套题】Codeforces#304(div2)

A. Soldier and Bananas 题意:第一个香蕉要k刀,第二个2k刀,第i个要i?k刀.现有n刀,问可以买几个香蕉. 题解:等差数列求和,我们知道只需要找到p使得 ∑i=1pi?k≤n<∑i=1p+1i?k 即可,移项就可以得到公式,同时上述求和公式是单调递增的,因此也可以二分答案. 参考代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std;

CF#304Div2

A.Soldier and Bananas 题解:注意溢出以及不需要借钱的情况. 代码实现: #include <iostream> #include <bits/stdc++.h> using namespace std; int main() { long long Sum; long long K,N,W; cin>>K>>N>>W; Sum = (W+1)*W/2*K; if( Sum >= N ) Sum -= N; else S

网络流(最大流) CodeForces 546E:Soldier and Traveling

In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighb