【codeforces 546A】Soldier and Bananas

我不是女神ヾ 2021-10-26 17:18 303阅读 0赞

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!!!!
否则输出差的绝对值就好.
细心。

【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define rei(x) scanf("%d",&x)
  13. #define rel(x) scanf("%I64d",&x)
  14. typedef pair<int,int> pii;
  15. typedef pair<LL,LL> pll;
  16. //const int MAXN = x;
  17. const int dx[9] = {
  18. 0,1,-1,0,0,-1,-1,1,1};
  19. const int dy[9] = {
  20. 0,0,0,-1,1,-1,1,-1,1};
  21. const double pi = acos(-1.0);
  22. LL k,n,w;
  23. int main()
  24. {
  25. //freopen("F:\\rush.txt","r",stdin);
  26. rel(k);rel(n);rel(w);
  27. LL temp1 = (k + w*k)*w/2;
  28. LL temp = n-temp1;
  29. if (temp <0)
  30. cout << abs(temp)<<endl;
  31. else
  32. puts("0");
  33. return 0;
  34. }

转载于:https://www.cnblogs.com/AWCXV/p/7626763.html

发表评论

表情:
评论列表 (有 0 条评论,303人围观)

还没有评论,来说两句吧...

相关阅读