##CF 1792B
原题链接: https://codeforces.com/problemset/problem/1792/B
题目不难,但是数据很恶心,很容易超时的,所以基本上是不能用for循环来写,尽量全用if else 语句,基本上O(1)能过的;
唯一要注意的是,表面上有两个人,但是只要看一个人的就行,因为有一个人一直是最低的
#include<bits/stdc++.h>
using namespace std;
const int N = 200010;
typedef long long ll;
int main()
{
int t;
cin >> t;
while (t--)
{
ll a, b, c, d;
//用res来记录情绪最低的那一个人的情绪数值
ll ans = 0, res=0;
cin >> a >> b >> c >> d;
ans += a;
res += a;
//如果没有两个都喜欢的情绪,那肯定后面无论讲什么都会有一个人情绪
//为负,所以上只可能讲一个
if (a == 0)
{
cout << 1 << endl;
continue;
}
//我们可以一人讲一个喜欢的,只要取他们的最小值就是相当于两个人的情绪
//不变但是笑话都变多,这样也是最经济的选法
ans += (min(b, c) * 2);
//接下来我们要判断情绪最低的人会不会情绪为负
int te = abs(b - c);
//会
if (te > res)
{
//注意是为负所以加一,结束运算
ans += res+1;
//cout << res << endl;
cout << ans << endl;
continue;
}
//不会
else
{
res -= te;
ans += te;
}
//继续判断
if (res >= d)
{
ans += d;
}
else
{
//同上
ans += res+1;
}
cout << ans << endl;
}
return 0;
}