Problem p00100 (C++) — buggy submission, verdict: Runtime Error

/*
    ????????°??§???????????¨????????????
*/

#include <algorithm>
#include <ctype.h>
#include <float.h>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\\n")
#define debugd(a) printf("--%d\\n", a)
#define debugdd(a, b) printf("--%d %d\\n", a, b)
#define debugarr(a, b)                                                         \\
  for (int i = 0; i < b; i++)                                                  \\
    printf("%d ", a[i]);                                                       \\
  printf("\\n")
#define newline printf("\\n")
#define forin(a, b, c) for (int a = b; a < c; a++)
#define forde(a, b, c) for (int a = b; a >= c; a--)

inline void scd(int &a) { scanf("%d", &a); }
inline void scdd(int &a, int &b) { scanf("%d %d", &a, &b); }
inline void sctd(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
inline void scdlld(LL &a, LL &b) { scanf("%I64d %I64d", &a, &b); }
inline void sclld(LL &a) { scanf("%I64d", &a); }

#define scarrd(a, b)                                                           \\
  for (int index = 0; index < b; index++)                                      \\
  scanf("%d", &a[index])
#define prdlld(a, b) printf("%I64d %I64d", a, b)
#define prdd(a, b) printf("%d %d", a, b)
#define prd(a) printf("%d", a)
#define prarr(a, b)                                                            \\
  for (int i = 0; i < b; i++)                                                  \\
  printf("%d ", a[i])
#define iniarr(a, b)                                                           \\
  for (int i = 0; i < b; i++)                                                  \\
  a[i] = 0
#define arr(a, b) int *a = (int *)malloc(b * sizeof(int))
#define llarr(a, b)                                                            \\
  long long int *a = (long long int *)malloc(b * sizeof(long long int))
#define st(a, b) char *a = (char *)malloc(b * sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main() {
  int n;
  scd(n);
  LL a, b;
  string c;
  while (n != 0) {
    vector<string> e;
    map<string, LL> d;
    int fl = 0;
    forin(i, 0, n) {
      cin >> c >> a >> b;
      fl = 0;
      forin(i, 0, e.size()) {
        if (e[i] == c) {
          fl = 1;
          break;
        }
      }
      if (fl == 0)
        e.pb(c);

      d[c] += a * b;
    }
    fl = 0;
    int size = e.size();
    forin(i, 0, size) {
      if (d[e[i]] >= 1000000) {
        fl = 1;
        cout << e[i] << endl;
      }
    }

    if (fl == 0)
      printf("NA\\n");

    scd(n);
  }

  return 0;
}

Error: TLE

Fixed submission:

/*
    ????????°??§???????????¨????????????
*/

#include <algorithm>
#include <ctype.h>
#include <float.h>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\\n")
#define debugd(a) printf("--%d\\n", a)
#define debugdd(a, b) printf("--%d %d\\n", a, b)
#define debugarr(a, b)                                                         \\
  for (int i = 0; i < b; i++)                                                  \\
    printf("%d ", a[i]);                                                       \\
  printf("\\n")
#define newline printf("\\n")
#define forin(a, b, c) for (int a = b; a < c; a++)
#define forde(a, b, c) for (int a = b; a >= c; a--)

inline void scd(int &a) { scanf("%d", &a); }
inline void scdd(int &a, int &b) { scanf("%d %d", &a, &b); }
inline void sctd(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
inline void scdlld(LL &a, LL &b) { scanf("%I64d %I64d", &a, &b); }
inline void sclld(LL &a) { scanf("%I64d", &a); }

#define scarrd(a, b)                                                           \\
  for (int index = 0; index < b; index++)                                      \\
  scanf("%d", &a[index])
#define prdlld(a, b) printf("%I64d %I64d", a, b)
#define prdd(a, b) printf("%d %d", a, b)
#define prd(a) printf("%d", a)
#define prarr(a, b)                                                            \\
  for (int i = 0; i < b; i++)                                                  \\
  printf("%d ", a[i])
#define iniarr(a, b)                                                           \\
  for (int i = 0; i < b; i++)                                                  \\
  a[i] = 0
#define arr(a, b) int *a = (int *)malloc(b * sizeof(int))
#define llarr(a, b)                                                            \\
  long long int *a = (long long int *)malloc(b * sizeof(long long int))
#define st(a, b) char *a = (char *)malloc(b * sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  scd(n);
  LL a, b;
  string c;
  vector<tuple<string, LL, LL>> d;
  while (n != 0) {
    d.clear();
    int fl = 0;
    forin(i, 0, n) {
      cin >> c;
      scdlld(a, b);
      d.pb(make_tuple(c, a, b));
    }
    sort(d.begin(), d.end());

    int size = d.size();
    LL z = 0;
    int l = 0;
    int flag;
    for (int i = 0; i < size; i++) {
      flag = 0;
      a = get<1>(d[i]) * get<2>(d[i]);
      for (int j = i + 1; j < size; j++) {
        if (get<0>(d[i]) == get<0>(d[j])) {
          l = j;
          flag = 1;
          a += get<1>(d[j]) * get<2>(d[j]);
        } else
          break;
      }
      // cout<<get<0>(d[i])<<"---"<<i<<endl;
      if (flag == 1) {
        i += l;
        // cout<<get<0>(d[i])<<"--"<<i<<endl;
      }

      if (a >= 1000000) {
        cout << get<0>(d[i]) << endl;
        fl = 1;
      }
    }

    if (fl == 0)
      printf("NA\\n");

    scd(n);
  }

  return 0;
}