Problem p00276 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  int Q;
  cin >> Q;
  rep(i, Q) {
    int c, a, n;
    cin >> c >> a >> n;
    ll ans = 0;
    while (c >= 1 && a >= 1 && n >= 1) {
      ans++;
      c -= 1;
      a -= 1;
      n -= 1;
    }
    while (c >= 2 && a >= 1) {
      ans++;
      c -= 2, a -= 1;
    }
    while (c >= 3) {
      ans++;
      c -= 3;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
ll ans = 0;
void dfs(vi gotiusa, int a) {
  cmax(ans, a);
  if (gotiusa[0] >= 3) {
    vi temp = gotiusa;
    temp[0] -= 3;
    dfs(temp, a + 1);
  }
  if (gotiusa[0] >= 2 && gotiusa[1] >= 1) {
    vi temp = gotiusa;
    temp[0] -= 2;
    temp[1] -= 1;
    dfs(temp, a + 1);
  }
  if (gotiusa[0] >= 1 && gotiusa[1] >= 1 && gotiusa[2] >= 1) {
    vi temp = gotiusa;
    rep(i, 3) temp[i] -= 1;
    dfs(temp, a + 1);
  }
}
int main() {
  int n;
  cin >> n;
  rep(i, n) {
    ans = 0;
    vi gotiusa;
    int rize, syaro, tiya;
    cin >> rize >> syaro >> tiya;
    gotiusa.push_back(rize);
    gotiusa.push_back(syaro);
    gotiusa.push_back(tiya);
    dfs(gotiusa, 0);
    cout << ans << endl;
  }
}