传送门:洛谷 Hard Problem | Codeforces C. Hard Problem
更佳的阅读体验:CF2044C 题解
简要题意:教室里有两排座位,每排有 $m$ 个。$a$ 只猴子坐在第一排,$b$ 只猴子坐在第二排,$c$ 只猴子坐在剩下的位置上,问最多可以坐多少猴子。
因为 $c$ 只猴子可以坐到任意一排,所以我们只需要优先考虑必须坐在第一排的 $a$ 个和第二排的 $b$ 只猴子,将剩余的位置尽可能多的安排给剩下的 $c$ 只猴子即可。
#include <iostream>
using namespace std;
int t, m, a, b, c, cnta, cntb;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (cin >> t; t; --t) {
cin >> m >> a >> b >> c;
cnta = min(m, a), cntb = min(m, b);
cout << cnta + cntb + min((m << 1) - cnta - cntb, c) << '\n';
} return 0;
}