codeforces 571 A. Lengthening Sticks

A. Lengthening Sticks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the length of any stick.

Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.

Input

The single line contains 4 integers a, b, c, l (1 ≤ a, b, c ≤ 3·1050 ≤ l ≤ 3·105).

Output

Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most l centimeters, so that you can make a non-degenerate triangle from it.

Sample test(s)
input
1 1 1 2
output
4
input
1 2 3 1
output
2
input
10 2 1 7
output
0
Note

In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter.

In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.



思路:枚举最长边,用容斥来做

#include <iostream>
#include <cstdio>
using namespace std;

#define LL __int64

LL deal(LL a, LL b, LL c, LL r) {
	if(a < b + c) return 0;
	LL tmp = min(r, a - (b + c));
	return (tmp + 1) * (tmp + 2) / 2;
}

void gao(LL a, LL b, LL c, LL l) {
	LL ans = (l + 1) * (l + 2) * (l + 3) / 6;

	for(int i = 0; i <= l; ++i) {
		ans -= deal(a + i, b, c, l - i);
		ans -= deal(b + i, a, c, l - i);
		ans -= deal(c + i, a, b, l - i);
	}

	cout<<ans<<endl;
}

int main() {
	LL a, b, c, l;
	cin >> a >> b >> c >> l;
	gao(a, b, c, l);
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值