Problem p00196 (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 n;
  while (cin >> n, n) {
    vector<pii> ujimatsu(n, pii(0, 0));
    vc anko(n);
    rep(i, n) {
      cin >> anko[i];
      rep(j, n - 1) {
        int tiya;
        cin >> tiya;
        if (tiya == 0)
          ujimatsu[i].first += 100000000;
        else if (tiya == 1)
          ujimatsu[i].second += 1;
        else if (tiya == 2)
          ujimatsu[i].first += 1;
      }
    }
    vector<bool> flag(1000, true);
    rep(i, n) {
      int maxi = -INF;
      int ans = 0;
      rep(j, n) {
        if (!flag[j])
          continue;
        if (ujimatsu[j].first > maxi) {
          maxi = ujimatsu[j].first;
          ans = j;
        } else if (ujimatsu[j].first == maxi) {
          if (ujimatsu[ans].second > ujimatsu[j].second) {
            ans = j;
          }
        }
      }
      flag[ans] = false;
      cout << anko[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;
int main() {
  int n;
  while (cin >> n, n) {
    vi v(7, 0);
    rep(i, n) {
      int gotiusa_is_a_god_especially_tiya;
      cin >> gotiusa_is_a_god_especially_tiya;
      if (gotiusa_is_a_god_especially_tiya >= 60)
        gotiusa_is_a_god_especially_tiya = 60;
      v[gotiusa_is_a_god_especially_tiya / 10]++;
    }
    rep(i, 7) cout << v[i] << endl;
  }
}