链接:https://ac.nowcoder.com/acm/contest/8688/A
来源:牛客网
题目描述
You are given four positive integers 𝑥, 𝑦, 𝑧, 𝑘, please help little M calculate the number of equations 𝑥 + 𝑦 + 𝑧 = 𝑘 when 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑
输入描述:
Four integers 𝑎, 𝑏, 𝑐, 𝑑 (0 ≤ 𝑎, 𝑏, 𝑐, 𝑑 ≤10^610
6
)
输出描述:
One integer the number of equations.
It is guaranteed that all the answers fit 64-bit integer.
示例1
输入
复制
3 3 3 3
输出
复制
20
示例2
输入
复制
300 300 300 300
输出
复制
4590551
示例3
输入
复制
0 0 0 0
输出
复制
1
示例4
输入
复制
12345 12345 12345 12345
输出
复制
313713415596
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll ans[N];
ll a[5];
int main() {
ll d,ansp=0;
cin>>a[0]>>a[1]>>a[2]>>d;
sort(a,a+3);
for(int i=0; i<=d; i++) {
if(a[1]>=i)
ans[i]=i+1;
else {
if(a[2]>=i)
ans[i]=a[1]+1;
else if(a[2]+a[1]>=i)
ans[i]=a[1]-(i-a[2])+1;
}
}
for(int i=0; i<=d; i++) {
ll p=min(a[0]+1,d-i+1);
ansp+=p*ans[i];
}
cout<<ansp<<endl;
return 0;
}