Problem p03371 (C++)

Buggy submission (status: Time Limit Exceeded):

/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define _ printf("\n")
int take() {
  int n;
  scanf("%d", &n);
  return n;
}
double ttake() {
  double n;
  scanf("%lf", &n);
  return n;
}
ll takes() {
  ll n;
  scanf("%lld", &n);
  return n;
}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done                                                                   \
  { return 0; }
#define fr(i, x, n, a) for (int i = x; i <= n; i += a)
#define FR(a, b, x) for (int i = (a); i <= (b); i += (x))
#define rfr(i, x, n, a) for (int i = x; i >= n; i--)
int cas;
#define print printf("Case %d:", ++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int, int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define mk make_pair
#define fill(x, v) memset(x, v, sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
  return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
  return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR                                                                    \
  { struct info }
#define dbg(x)                                                                 \
  { cout << "ekhane" << x << endl; }
#define SS second
#define FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int, int>
#define mil map<int, ll>
#define mll map<ll, ll>
#define msb map<string, bool>
#define V vector
#define M 100005
#define pf printf
//////////////////////////////////////////

int main() {

  ll a = LL, b = LL, c = LL, x = LL, y = LL;
  ll ans = 1000000000000000000;

  fr(i, 0, x, 1) {
    fr(k, 0, y, 1) {
      ll d = i, e = k;
      ll f = d * a + e * b;
      ll g = max(x - i, y - k) * 2ll * c;
      ans = min(ans, f + g);
    }
  }
  pf("%lld\n", ans);
  done;
}


Fixed submission:

/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define _ printf("\n")
int take() {
  int n;
  scanf("%d", &n);
  return n;
}
double ttake() {
  double n;
  scanf("%lf", &n);
  return n;
}
ll takes() {
  ll n;
  scanf("%lld", &n);
  return n;
}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done                                                                   \
  { return 0; }
#define fr(i, x, n, a) for (int i = x; i <= n; i += a)
#define FR(a, b, x) for (int i = (a); i <= (b); i += (x))
#define rfr(i, x, n, a) for (int i = x; i >= n; i--)
int cas;
#define print printf("Case %d:", ++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int, int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define mk make_pair
#define fill(x, v) memset(x, v, sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
  return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
  return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR                                                                    \
  { struct info }
#define dbg(x)                                                                 \
  { cout << "ekhane" << x << endl; }
#define SS second
#define FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int, int>
#define mil map<int, ll>
#define mll map<ll, ll>
#define msb map<string, bool>
#define V vector
#define M 100005
#define pf printf
//////////////////////////////////////////

int main() {

  ll a = LL, b = LL, c = LL, x = LL, y = LL;
  ll ans = 1000000000000000000;

  fr(i, 0, max(x, y), 1) {
    ll d = i;
    ll e = 2 * d * 1ll * c;
    ll f = (x - i) * 1ll * a;
    ll g = (y - i) * 1ll * b;
    ll m = e;
    if (f > 0)
      m += f;
    if (g > 0)
      m += g;
    ans = min(ans, m);
  }
  pf("%lld\n", ans);
  done;
}