fork download
  1. #include <bits/stdc++.h>
  2. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
  3. #define fi first
  4. #define se second
  5. #define el "\n"
  6. #define pb push_back
  7. #define sz(a) (int)a.size()
  8. #define FILL(a, x) memset(a, x, sizeof(a))
  9.  
  10. using namespace std;
  11. typedef long long ll;
  12. typedef pair<int, int> ii;
  13. const int N = (int)1e6+3;
  14. ll a, b, c, d, B, G, R, Max;
  15. int T;
  16.  
  17. ll Tinh(ll x){
  18. return min(a, B - x) + min(b, x) + min(c, G - x) + min(d, x);
  19. }
  20.  
  21. ll Doi(ll a, ll b){
  22. if (a&1)
  23. {
  24. if (b%2==0) b--;
  25. }else if (b&1) b--;
  26. return b;
  27. }
  28.  
  29. int main()
  30. {
  31. ios_base::sync_with_stdio(false);
  32. cin.tie(NULL); cout.tie(NULL);
  33. freopen("pair.inp", "r", stdin);
  34. freopen("pair.out", "w", stdout);
  35. cin >> T;
  36. while(T--){
  37. cin >> a >> b >> c >> d;
  38. B = a + b;
  39. G = c + d;
  40. R = min(B, G);
  41. Max = -1e18;
  42. Max = Tinh(B%2);
  43. Max = max(Max, Tinh(Doi(B%2, R)));
  44. Max = max(Max, Tinh(Doi(B%2, b)));
  45. Max = max(Max, Tinh(Doi(B%2, d)));
  46. Max = max(Max, Tinh(Doi(B%2, B-a)));
  47. Max = max(Max, Tinh(Doi(B%2, G-c)));
  48. cout << Max << " ";
  49. }
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty