prithivMLmods/Coder-Stat huggingface dataset:
Problem p03594 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

const i64 INF = 1e18 + 7;

signed main() {
  int h, w, d;
  cin >> h >> w >> d;
  vector<vector<int>> v(1002, vector<int>(1002, -1));
  array<bitset<1002>, 1002> use;
  map<pair<int, int>, pair<int, int>> p;

  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      int x = i + j, y = i - j + 500;
      use[x].set(y);
    }

  if (d & 1) {
    for (int i = 0; i < 1002; ++i)
      for (int j = 0; j < 1002; ++j)
        v[i][j] = i % 2;
  } else {
    abort();
  }

  auto print = [&] {
    string s = "RYGB";
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        int x = i + j, y = i - j + 500;
        cout << s[v[x][y]];
      }
      cout << endl;
    }
  };

  print();
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

const i64 INF = 1e18 + 7;

signed main() {
  int h, w, d;
  cin >> h >> w >> d;
  vector<vector<int>> v(1002, vector<int>(1002, -1));
  array<bitset<1002>, 1002> use;
  map<pair<int, int>, pair<int, int>> p;

  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      int x = i + j, y = i - j + 500;
      use[x].set(y);
    }

  if (d & 1) {
    for (int i = 0; i < 1002; ++i)
      for (int j = 0; j < 1002; ++j)
        v[i][j] = i % 2;
  } else {
    for (int i = 0; i < 1002; ++i)
      for (int j = 0; j < 1002; ++j) {
        int f1 = i % (2 * d) >= d;
        int f2 = j % (2 * d) >= d;
        v[i][j] = f1 + 2 * f2;
      }
  }

  auto print = [&] {
    string s = "RYGB";
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        int x = i + j, y = i - j + 500;
        cout << s[v[x][y]];
      }
      cout << endl;
    }
  };

  print();
}
Problem p03597 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int n, a;
int main() {
  scanf("%d", n);
  scanf("%d", a);
  printf("%d\n", n * n - a);
  return 0;
}

Fixed submission:
#include <stdio.h>
int n, a;
int main() {
  scanf("%d", &n);
  scanf("%d", &a);
  printf("%d\n", n * n - a);
  return 0;
}
Problem p03597 (Python)

Buggy submission (status: Runtime Error):
# 入力 : 数字2つ
N, A = map(int, input().split())

# 出力　N^2-A
ans = N * N - A
print(ans)


Fixed submission:
# 入力 : 数字2つ
N = int(input())
A = int(input())

# 出力　N^2-A
ans = N * N - A
print(ans)
Problem p03597 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
print(N * N - M)


Fixed submission:
N = int(input())
M = int(input())
print(N * N - M)
Problem p03597 (Python)

Buggy submission (status: Runtime Error):
N, A = [input() for i in range(2)]
print(N**2 - A)


Fixed submission:
N, A = [int(input()) for i in range(2)]
print(N**2 - A)
Problem p03597 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().split())
print(a * a - b)


Fixed submission:
a = int(input())
b = int(input())
print(a * a - b)
Problem p03597 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

int main() {
  int n, a;
  scanf("%d%d", n, a);
  printf("%d\n", n ^ 2 - a);
}


Fixed submission:
#include <iostream>

int main() {
  int n, a;
  scanf("%d", &n);
  scanf("%d", &a);
  printf("%d\n", n * n - a);
}
Problem p03597 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int MAXN = 10010;

int main() {
  int N, A, ans;

  cin >> N;
  cin >> A;
  ans = N * N - A;
  // printf("%d",ans);
  return ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int MAXN = 10010;

int main() {
  int N, A;
  cin >> N >> A;
  cout << N * N - A << endl;
}
Problem p03597 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, A;

  cin >> N >> A;
  cout << N * N % A << endl; // ここにプログラムを追記
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, A;

  cin >> N >> A;
  cout << N * N - A << endl; // ここにプログラムを追記
}
Problem p03597 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, A;

  cin >> N >> A;

  N = N * N;

  N = N % A;

  cout << N << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, A;

  cin >> N >> A;

  cout << N * N - A << endl;
}
Problem p03597 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int n, a;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  cin >> n >> a;
  cout << n * n - a;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int n, a;
int main() {

  cin >> n >> a;
  cout << n * n - a;
}
Problem p03598 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

// -------------------
// ここから先は変更しない
// -------------------
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> X;
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (X.at(i) < K - X.at(i)) {
      sum += X.at(i);
    } else {
      sum += K - X.at(i);
    }
  }
  cout << sum * 2 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

// -------------------
// ここから先は変更しない
// -------------------
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (X.at(i) < K - X.at(i)) {
      sum += X.at(i);
    } else {
      sum += K - X.at(i);
    }
  }
  cout << sum * 2 << endl;
}
Problem p03598 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, k, x[100], ans = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", x[i]);
    ans += 2 * (min(x[i], k - x[i]));
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, k, x[100], ans = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
    ans += 2 * (min(x[i], k - x[i]));
  }
  printf("%d\n", ans);
}
Problem p03598 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vll X(K);
  REP(i, 0, N) {
    ll x;
    cin >> x;
    X[i] = x;
  }

  ll result = 0;
  REP(i, 0, N) {
    if (abs(K - X[i]) < abs(0 - X[i])) {
      result += abs(K - X[i]) * 2;
    } else {
      result += X[i] * 2;
    }
  }
  cout << result << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vll X(N);
  REP(i, 0, N) {
    ll x;
    cin >> x;
    X[i] = x;
  }

  ll result = 0;
  REP(i, 0, N) {
    if (abs(K - X[i]) < abs(0 - X[i])) {
      result += abs(K - X[i]) * 2;
    } else {
      result += X[i] * 2;
    }
  }
  cout << result << endl;

  return 0;
}
Problem p03598 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int K;
  int i = 0;
  int sum = 0;
  cin >> N >> K;
  while (i < N) {
    int a;
    cin >> a;
    if (a >= K - a) {
      sum = sum + 2 * K - 2 * a;
    } else {
      sum += 2 * a;
    }
  }
  cout << sum << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int K;
  int i = 0;
  int sum = 0;
  cin >> N >> K;
  while (i < N) {
    int a;
    cin >> a;
    if (a >= K - a) {
      sum = sum + 2 * K - 2 * a;
    } else {
      sum += 2 * a;
    }
    i++;
  }
  cout << sum << endl;
}
Problem p03598 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k, nm = 0;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= n; i++) {
    if (x[i] != k - x[i]) {
      nm += min(x[i] * 2, 2 * (k - x[i]));
    } else {
      nm += x[i] * 2;
    }
  }
  cout << nm << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k, nm = 0;
  cin >> n >> k;
  vector<int> x(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= n; i++) {
    if (x[i] != k - x[i]) {
      nm += min(x[i] * 2, 2 * (k - x[i]));
    } else {
      nm += x[i] * 2;
    }
  }
  cout << nm << endl;
}
Problem p03598 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  int i;
  vector<int> x(n);
  for (i = 0; i < n; i++) {
    cin >> x.at(n);
  }

  int ans = 0;
  for (i = 0; i < n; i++) {
    ans += 2 * min(x.at(i), abs(k - x.at(i)));
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  int i;
  vector<int> x(n);
  for (i = 0; i < n; i++) {
    cin >> x.at(i);
  }

  int ans = 0;
  for (i = 0; i < n; i++) {
    ans += 2 * min(x.at(i), abs(k - x.at(i)));
  }

  cout << ans << endl;
}
Problem p03599 (Python)

Buggy submission (status: Runtime Error):
A, B, C, D, E, F = map(int, input().split())

ans = []
max_conc = 0
for a in range(F // 100 + 1):
    left = F - 100 * a * A
    for b in range(left // 100 + 1):
        w = 100 * a * A + 100 * b * B

        s_max = min(F - w, w * E // 100)
        if s_max >= 0:
            for c in range(s_max // C + 1):
                d = (s_max - c * C) // D

                if d >= 0:
                    # suger
                    s = c * C + d * D
                    if s + w > 0:
                        conc = s / (s + w)
                        if conc > max_conc:
                            ans = [s, w]
                            max_conc = conc


print(str(ans[0] + ans[1]) + " " + str(ans[0]))


Fixed submission:
A, B, C, D, E, F = map(int, input().split())

ans = [0, 0]
max_conc = -1
for a in range(F // 100 + 1):
    left = F - 100 * a * A
    for b in range(left // 100 + 1):
        w = 100 * a * A + 100 * b * B

        s_max = min(F - w, w * E // 100)
        if s_max >= 0:
            for c in range(s_max // C + 1):
                d = (s_max - c * C) // D

                if d >= 0:
                    # suger
                    s = c * C + d * D
                    if s + w > 0:
                        conc = s / (s + w)
                        if conc > max_conc:
                            ans = [s, w]
                            max_conc = conc


print(str(ans[0] + ans[1]) + " " + str(ans[0]))
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> water;
  vector<int> sugar;

  for (int i = 0; i < (F / 100); i++) {
    for (int j = 0; j < (F / 100); j++) {
      water.push_back(100 * A * i + 100 * B * j);
    }
  }

  for (int i = 0; i < F; i++) {
    for (int j = 0; j < F; j++) {
      sugar.push_back(C * i + D * j);
    }
  }

  double result_con = 0.0;
  int result_sugar = 0;
  int result_weight = 0;

  for (unsigned int i = 0; i < water.size(); i++) {
    for (unsigned int j = 0; j < sugar.size(); j++) {
      // printf("water : %d, sugar : %d\n",water[i], sugar[j]);
      if (water[i] + sugar[j] > F) {
        continue;
      }
      if (water[i] / 100 * E < sugar[j]) {
        continue;
      }
      double con = (double)sugar[j] / (double)(water[i] + sugar[j]);
      if (result_con <= con) {
        result_con = con;
        result_sugar = sugar[j];
        result_weight = sugar[j] + water[i];
      }
    }
  }

  cout << result_weight << " " << result_sugar << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> water;
  vector<int> sugar;

  for (int i = 0; i < (F / 100); i++) {
    for (int j = 0; j < (F / 100); j++) {
      water.push_back(100 * A * i + 100 * B * j);
    }
  }

  for (int i = 0; i < F / C; i++) {
    for (int j = 0; j < F / D; j++) {
      sugar.push_back(C * i + D * j);
    }
  }

  double result_con = 0.0;
  int result_sugar = 0;
  int result_weight = 0;

  for (unsigned int i = 0; i < water.size(); i++) {
    for (unsigned int j = 0; j < sugar.size(); j++) {
      // printf("water : %d, sugar : %d\n",water[i], sugar[j]);
      if (water[i] + sugar[j] > F) {
        continue;
      }
      if (water[i] / 100 * E < sugar[j]) {
        continue;
      }
      double con = (double)sugar[j] / (double)(water[i] + sugar[j]);
      if (result_con <= con) {
        result_con = con;
        result_sugar = sugar[j];
        result_weight = sugar[j] + water[i];
      }
    }
  }

  cout << result_weight << " " << result_sugar << endl;

  return 0;
}
Problem p03599 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int a, b, c, d, e, f;
int wat[100000];
int sug[100000];
int cntw = 0;
int cnts = 0;

int main() {
  cin >> a >> b >> c >> d >> e >> f;
  for (int i = 0; i <= f; i += (100 * a)) {
    for (int j = 0; j <= f; j += (100 * b)) {
      if (i + j > f) {
        continue;
      }
      wat[cntw] = i + j;
      cntw += 1;
    }
  }
  for (int i = 0; i <= f; i += c) {
    for (int j = 0; j <= f; j += d) {
      if (i + j > f) {
        continue;
      }
      sug[cnts] = i + j;
      cnts += 1;
    }
  }
  double maxc = -1.0;
  double answ = 0, anss = 0;
  for (int i = 0; i < cntw; i++) {
    for (int j = 0; j < cnts; j++) {
      if (wat[i] + sug[j] > f) {
        continue;
      }
      if (wat[i] * e < 100 * sug[j]) {
        continue;
      }
      double ii = (double)wat[i];
      double jj = (double)sug[j];
      if ((100.0 * jj) / (ii + jj) > maxc) {
        maxc = (100.0 * jj) / (ii + jj);
        answ = wat[i] + sug[j];
        anss = sug[j];
      }
    }
  }
  cout << answ << " " << anss << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int a, b, c, d, e, f;
int wat[1000000];
int sug[1000000];
int cntw = 0;
int cnts = 0;

int main() {
  cin >> a >> b >> c >> d >> e >> f;
  for (int i = 0; i <= f; i += (100 * a)) {
    for (int j = 0; j <= f; j += (100 * b)) {
      if (i + j > f) {
        continue;
      }
      wat[cntw] = i + j;
      cntw += 1;
    }
  }
  for (int i = 0; i <= f; i += c) {
    for (int j = 0; j <= f; j += d) {
      if (i + j > f) {
        continue;
      }
      sug[cnts] = i + j;
      cnts += 1;
    }
  }
  double maxc = -1.0;
  double answ = 0, anss = 0;
  for (int i = 0; i < cntw; i++) {
    for (int j = 0; j < cnts; j++) {
      if (wat[i] + sug[j] > f) {
        continue;
      }
      if (wat[i] * e < 100 * sug[j]) {
        continue;
      }
      double ii = (double)wat[i];
      double jj = (double)sug[j];
      if ((100.0 * jj) / (ii + jj) > maxc) {
        maxc = (100.0 * jj) / (ii + jj);
        answ = wat[i] + sug[j];
        anss = sug[j];
      }
    }
  }
  cout << answ << " " << anss << endl;
}
Problem p03599 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int search_max_sugar(int max_sugar, set<int> &s) {
  int res = 0;
  for (auto s1 : s) {
    if (s1 > max_sugar) {
      break;
    }
    res = s1;
  }
  return res;
}

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  set<int> water, sugar;
  for (int i = 0; 100 * a * i <= f; i++) {
    for (int j = 0; 100 * a * i + 100 * b * j <= f; j++) {
      water.insert(100 * a * i + 100 * b * j);
    }
  }
  for (int i = 0; c * i <= f; i++) {
    for (int j = 0; c * i + d * j <= f; j++) {
      sugar.insert(c * i + d * j);
    }
  }
  pair<int, int> ans;
  int tmp;
  double max_cardinality = 0.0;
  for (auto s : water) {
    tmp = search_max_sugar(min(e * s / 100, f - s), sugar);
    double cardinality = 100 * tmp / (s + tmp);
    if (max_cardinality <= cardinality) {
      max_cardinality = cardinality;
      ans.first = s + tmp;
      ans.second = tmp;
    }
  }

  cout << ans.first << " " << ans.second << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int search_max_sugar(int max_sugar, set<int> &s) {
  int res = 0;
  for (auto s1 : s) {
    if (s1 > max_sugar) {
      break;
    }
    res = s1;
  }
  return res;
}

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  set<int> water, sugar;
  for (int i = 0; 100 * a * i <= f; i++) {
    for (int j = 0; 100 * a * i + 100 * b * j <= f; j++) {
      water.insert(100 * a * i + 100 * b * j);
    }
  }
  for (int i = 0; c * i <= f; i++) {
    for (int j = 0; c * i + d * j <= f; j++) {
      sugar.insert(c * i + d * j);
    }
  }
  pair<int, int> ans;
  int tmp;
  double max_cardinality = 0.0;
  for (auto s : water) {
    tmp = search_max_sugar(min(e * s / 100, f - s), sugar);
    double cardinality = (double)100 * tmp / (s + tmp);
    if (max_cardinality <= cardinality) {
      max_cardinality = cardinality;
      ans.first = s + tmp;
      ans.second = tmp;
    }
  }

  cout << ans.first << " " << ans.second << "\n";
  return 0;
}
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, start, end) for (int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  // i -> 水の量, j -> 砂糖の量
  double max_melt = -1.0;
  int water, sugar;
  rep(i, f + 1) {
    rep(j, f - i + 1) {
      bool flag = false;
      for (int k = 0; k <= j; k += c) {
        if (k == 0 && j % d == 0)
          flag = true;
        else if (k > 0 && j % k % d == 0)
          flag = true;
      }

      if (i % (a * 100) % (b * 100) == 0 && flag && j * 100 <= e * i) {
        double per = 100.0 * j / (i + j);
        if (max_melt < per) {
          water = i;
          sugar = j;
          max_melt = per;
        }
      }
    }
  }

  cout << water + sugar << " " << sugar << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, start, end) for (int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  // i -> 水の量, j -> 砂糖の量
  double max_melt = -1.0;
  int water, sugar;
  for (int i = 0; i <= f; i += 100 * a) {
    for (int j = 0; j <= f - i; j += 100 * b) {
      for (int k = 0; k <= f - i - j; k += c) {
        for (int l = 0; l <= f - i - j - k; l += d) {
          if ((k + l) * 100 <= e * (i + j)) {
            double per = 100.0 * (k + l) / (i + j + k + l);
            if (max_melt < per) {
              water = i + j;
              sugar = k + l;
              max_melt = per;
            }
          }
        }
      }
    }
  }

  cout << water + sugar << " " << sugar << endl;
}
Problem p03599 (Python)

Buggy submission (status: Runtime Error):
A, B, C, D, E, F = map(int, input().split())

w = set()
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        a = (A * i + B * j) * 100
        if a < F:
            w.append(a)
w.remove(0)

best_concentration = -1
best_a = -1
best_b = -1
for a in w:
    for i in range((F - a) // C + 1):
        for j in range((F - a) // D + 1):
            b = C * i + D * j
            if a + b > F:
                continue
            if b > E * a // 100:
                continue
            concentration = 100 * b / (a + b)
            if concentration > best_concentration:
                best_concentration = concentration
                best_a = a
                best_b = b
print(best_a + best_b, best_b)


Fixed submission:
A, B, C, D, E, F = map(int, input().split())

w = set()
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        a = (A * i + B * j) * 100
        if a < F:
            w.add(a)
w.remove(0)

best_concentration = -1
best_a = -1
best_b = -1
for a in w:
    for i in range((F - a) // C + 1):
        for j in range((F - a) // D + 1):
            b = C * i + D * j
            if a + b > F:
                continue
            if b > E * a // 100:
                continue
            concentration = 100 * b / (a + b)
            if concentration > best_concentration:
                best_concentration = concentration
                best_a = a
                best_b = b
print(best_a + best_b, best_b)
Problem p03599 (Python)

Buggy submission (status: Runtime Error):
A, B, C, D, E, F = list(map(int, input().split()))

water = set()
sugar = set()
res = {}
noudo = []

counter = max([int(F / A), int(F / B)])
A_counter = int(F / (A * 100))
B_counter = int(F / (B * 100))
for i in range(A_counter + 1):
    for j in range(B_counter + 1):
        tmp = A * i * 100 + B * 100 * j
        if tmp <= F:
            water.add(tmp)

C_counter = int(F / C)
D_counter = int(F / D)
for i in range(C_counter + 1):
    for j in range(D_counter + 1):
        tmp = i * C + D * j
        if tmp < F:
            sugar.add(tmp)

water.remove(0)
sugar.remove(0)

for w in water:
    for s in sugar:
        if w + s <= F and s <= E * (w / 100):
            n = s / (w + s)
            noudo.append(n)
            res[n] = {"satoumizu": w + s, "sugar": s}
ans = res[max(noudo)]
# print(" ".join([str(ans["satoumizu"]), str(ans["sugar"])]))
print(str(ans["satoumizu"]) + " " + str(ans["sugar"]))


Fixed submission:
A, B, C, D, E, F = list(map(int, input().split()))

water = set()
sugar = set()
res = {}
noudo = []

counter = max([int(F / A), int(F / B)])
A_counter = int(F / (A * 100))
B_counter = int(F / (B * 100))
for i in range(A_counter + 1):
    for j in range(B_counter + 1):
        tmp = A * i * 100 + B * 100 * j
        if tmp <= F:
            water.add(tmp)

C_counter = int(F / C)
D_counter = int(F / D)
for i in range(C_counter + 1):
    for j in range(D_counter + 1):
        tmp = i * C + D * j
        if tmp < F:
            sugar.add(tmp)

water.remove(0)
# sugar.remove(0)

for w in water:
    for s in sugar:
        if w + s <= F and s <= E * (w / 100):
            n = s / (w + s)
            noudo.append(n)
            res[n] = {"satoumizu": w + s, "sugar": s}
ans = res[max(noudo)]
# print(" ".join([str(ans["satoumizu"]), str(ans["sugar"])]))
print(str(ans["satoumizu"]) + " " + str(ans["sugar"]))
Problem p03599 (Python)

Buggy submission (status: Runtime Error):
from copy import deepcopy
import itertools

A, B, C, D, E, F = map(int, input().split())

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)


Fixed submission:
from copy import deepcopy
import itertools

A, B, C, D, E, F = map(int, input().split())

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
Ms = 0
Mw = A
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double min = 100;
  int sugarwater;
  int sugar;
  for (int a = 0; a <= 30; a++) {
    for (int b = 0; b <= 30; b++) {
      for (int c = 0; c <= 3000 / C; c++) {
        for (double d = 0; d <= (3000 - C * c) / D; d++) {
          if (C * c + D * d + 100 * A * a + 100 * B * b <= F) {
            if (E * (A * a + B * b) - (C * c + D * d) >= 0 and
                E * (A * a + B * b) - (C * c + D * d) < min * (A * a + B * b)) {
              min = E - (C * c + D * d) / (A * a + B * b);
              sugarwater = 100 * A * a + 100 * B * b + C * c + D * d;
              sugar = C * c + D * d;
            }
          }
        }
      }
    }
  }
  cout << sugarwater << endl;
  cout << sugar << endl;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double min = 100;
  int sugarwater;
  int sugar;
  for (int a = 0; a <= 30 / A; a++) {
    for (int b = 0; b <= (30 - A * a) / B; b++) {
      for (int c = 0; c <= 3000 / C; c++) {
        for (double d = 0; d <= (3000 - C * c) / D; d++) {
          if (C * c + D * d + 100 * A * a + 100 * B * b <= F) {
            if (E * (A * a + B * b) - (C * c + D * d) >= 0 and
                E * (A * a + B * b) - (C * c + D * d) < min * (A * a + B * b)) {
              min = E - (C * c + D * d) / (A * a + B * b);
              sugarwater = 100 * A * a + 100 * B * b + C * c + D * d;
              sugar = C * c + D * d;
            }
          }
        }
      }
    }
  }
  cout << sugarwater << endl;
  cout << sugar << endl;
}
Problem p03599 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  // 配列を使わない方がセグメント違反にならなかったりしていいかも
  int sw = 100 * A;
  int s = 0;
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      for (int k = 0; k < 101; k++) {
        for (int l = 0; l < 101; l++) {
          int xw = 100 * (A * i + B * j);
          int xs = C * k + D * l;
          if (xw + xs <= F) {
            if (xs * xw / 100 <= E) {
              if (100 * xs / (xw + xs) > 100 * s / (sw + s)) {
                sw = xw + xs;
                s = xs;
              }
            }
          }
        }
      }
    }
  }
  cout << sw << " " << s << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  // 配列を使わない方がセグメント違反にならなかったりしていいかも
  int sw = 100 * A;
  int s = 0;
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      for (int k = 0; k < 101; k++) {
        for (int l = 0; l < 101; l++) {
          int xw = 100 * (A * i + B * j);
          int xs = C * k + D * l;
          if (xw + xs <= F) {
            if (100 * xs <= xw * E) {
              if ((double)xs / (double)(xw + xs) > (double)s / (double)sw) {
                sw = xw + xs;
                s = xs;
              }
            }
          }
        }
      }
    }
  }
  cout << sw << " " << s << endl;
  return 0;
}
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

double get_percent(int water, int sugar) {
  return (100.0 * sugar) / (water + sugar);
}
int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  // percent is maximized + keeps ratio + under f
  double max = -1;
  pair<int, int> max_pair;
  for (int i = 0; i <= f; i++) {
    for (int j = 0; j <= f; j++) {
      for (int k = 0; k <= f; k++) {
        for (int l = 0; l <= f; l++) {
          int water = a * i + b * j;
          int sugar = c * k + d * l;
          int result = water * 100 + sugar;
          if (result > f) {
            continue;
          }
          if (sugar > e * water) {
            continue;
          }
          double ratio = get_percent(water * 100, sugar);
          if (ratio > max) {
            max = ratio;
            max_pair = make_pair(result, sugar);
          }
        }
      }
    }
  }
  cout << max_pair.first << " " << max_pair.second;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

double get_percent(int water, int sugar) {
  return (100.0 * sugar) / (water + sugar);
}
int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  // percent is maximized + keeps ratio + under f
  double max = -1;
  pair<int, int> max_pair;
  for (int i = 0; i * a * 100 <= f; i++) {
    for (int j = 0; i * a * 100 + j * b * 100 <= f; j++) {
      for (int k = 0; i * a * 100 + j * b * 100 + k * c <= f; k++) {
        for (int l = 0; i * a * 100 + j * b * 100 + k * c + l * d <= f; l++) {
          int water = a * i + b * j;
          int sugar = c * k + d * l;
          int result = water * 100 + sugar;
          if (result > f) {
            continue;
          }
          if (sugar > e * water) {
            continue;
          }
          double ratio = get_percent(water * 100, sugar);
          if (ratio > max) {
            max = ratio;
            max_pair = make_pair(result, sugar);
          }
        }
      }
    }
  }
  cout << max_pair.first << " " << max_pair.second;
  return 0;
}
Problem p03599 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < n; i++)
typedef long long int ll;

int main() {

  int a, b, c, d, e, f;

  cin >> a >> b >> c >> d >> e >> f;

  int rmt = f * e / 100;
  a *= 100;
  b *= 100;

  int cm = rmt / c;
  int dm = rmt / d;
  int su[cm + 1][dm + 1];

  for (int i = 0; i <= cm; i++) {
    for (int j = 0; j <= dm; j++) {
      su[i][j] = c * i + d * j;
    }
  }

  int am = f / a;
  int bm = f / b;
  int wa[am + 1][bm + 1];

  for (int i = 0; i <= am; i++) {
    for (int j = 0; j <= bm; j++) {
      wa[i][j] = a * i + b * j;
    }
  }

  int ans[4];
  double ma = 0.;

  for (int i = 0; i <= cm; i++) {
    for (int j = 0; j <= dm; j++) {
      for (int k = 0; k <= am; k++) {
        for (int l = 0; l <= bm; l++) {
          if (su[i][j] + wa[k][l] <= f && su[i][j] + wa[k][l] > 0) {
            if (su[i][j] <= wa[k][l] * e / 100) {
              if (ma < su[i][j] * 100.0 / (su[i][j] + wa[k][l])) {
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                ans[3] = l;
                ma = su[i][j] * 100.0 / (su[i][j] + wa[k][l]);
              }
            }
          }
        }
      }
    }
  }

  cout << su[ans[0]][ans[1]] + wa[ans[2]][ans[3]] << " " << su[ans[0]][ans[1]]
       << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < n; i++)
typedef long long int ll;

int main() {

  int a, b, c, d, e, f;

  cin >> a >> b >> c >> d >> e >> f;

  int rmt = f * e / 100;
  a *= 100;
  b *= 100;

  int cm = rmt / c;
  int dm = rmt / d;
  int su[cm + 1][dm + 1];

  for (int i = 0; i <= cm; i++) {
    for (int j = 0; j <= dm; j++) {
      su[i][j] = c * i + d * j;
    }
  }

  int am = f / a;
  int bm = f / b;
  int wa[am + 1][bm + 1];

  for (int i = 0; i <= am; i++) {
    for (int j = 0; j <= bm; j++) {
      wa[i][j] = a * i + b * j;
    }
  }

  int ans[4] = {0, 0, 1, 0};
  double ma = 0.0;

  for (int i = 0; i <= cm; i++) {
    for (int j = 0; j <= dm; j++) {
      for (int k = 0; k <= am; k++) {
        for (int l = 0; l <= bm; l++) {
          if (su[i][j] + wa[k][l] <= f && su[i][j] + wa[k][l] > 0) {
            if (su[i][j] <= wa[k][l] * e / 100) {
              if (ma < su[i][j] * 100.0 / (su[i][j] + wa[k][l])) {
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                ans[3] = l;
                ma = su[i][j] * 100.0 / (su[i][j] + wa[k][l]);
              }
            }
          }
        }
      }
    }
  }

  cout << su[ans[0]][ans[1]] + wa[ans[2]][ans[3]] << " " << su[ans[0]][ans[1]]
       << endl;

  return 0;
}
Problem p03599 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int a, b, c, d, e, f;
  vector<int> w(1, 0), s(1, 0);
  cin >> a >> b >> c >> d >> e >> f;
  for (int i = 0; a * i * 100 <= f; i++) {
    for (int j = 0; a * i * 100 + b * j * 100 <= f; j++) {
      w.push_back(a * i * 100 + b * j * 100);
    }
  }
  for (int i = 0; c * i <= f; i++) {
    for (int j = 0; c * i + d * j <= f; j++) {
      s.push_back(c * i + d * j);
    }
  }
  sort(w.begin(), w.end());
  sort(s.begin(), s.end());
  int m = -1, rsw, rs;
  for (auto &i : w) {
    int ts = *(upper_bound(s.begin(), s.end(), i * e / 100) - 1);
    if (i * 100.0f / ts > m && i + ts <= f) {
      m = i * 100 / ts;
      rsw = i + ts;
      rs = ts;
    }
  }
  cout << rsw << " " << rs;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int a, b, c, d, e, f;
  vector<int> w(1, 0), s(1, 0);
  cin >> a >> b >> c >> d >> e >> f;
  for (int i = 0; a * i * 100 <= f; i++) {
    for (int j = 0; a * i * 100 + b * j * 100 <= f; j++) {
      w.push_back(a * i * 100 + b * j * 100);
    }
  }
  for (int i = 0; c * i <= f; i++) {
    for (int j = 0; c * i + d * j <= f; j++) {
      s.push_back(c * i + d * j);
    }
  }
  float m = -1;
  int rsw = 0, rs = 0;
  for (auto i : w) {
    for (auto j : s) {
      if (j * 100.0f / (j + i) > m && i + j <= f && i * e / 100 >= j) {
        m = j * 100.0f / (j + i);
        rsw = i + j;
        rs = j;
      }
    }
  }
  cout << rsw << " " << rs;
}
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double min = 100;
  int sugarwater;
  int sugar;
  for (int a = 0; a <= 30; a++) {
    for (int b = 0; b <= 30; b++) {
      for (int c = 0; c <= 3000; c++) {
        for (double d = 0; d <= 3000; d++) {
          if (C * c + D * d + 100 * A * a + 100 * B * b <= F) {
            if (E * (A * a + B * b) - (C * c + D * d) >= 0 and
                E * (A * a + B * b) - (C * c + D * d) < min * (A * a + B * b)) {
              min = E - (C * c + D * d) / (A * a + B * b);
              sugarwater = 100 * A * a + 100 * B * b + C * c + D * d;
              sugar = C * c + D * d;
            }
          }
        }
      }
    }
  }
  cout << sugarwater << endl;
  cout << sugar << endl;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double min = 100;
  int sugarwater;
  int sugar;
  for (int a = 0; a <= 30; a++) {
    for (int b = 0; b <= 30; b++) {
      for (int c = 0; c <= 100; c++) {
        for (double d = 0; d <= 100; d++) {
          if (C * c + D * d + 100 * A * a + 100 * B * b <= F) {
            if (E * (A * a + B * b) - (C * c + D * d) >= 0 and
                E * (A * a + B * b) - (C * c + D * d) < min * (A * a + B * b)) {
              min = E - (C * c + D * d) / (A * a + B * b);
              sugarwater = 100 * A * a + 100 * B * b + C * c + D * d;
              sugar = C * c + D * d;
            }
          }
        }
      }
    }
  }
  cout << sugarwater << endl;
  cout << sugar << endl;
}
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  int maxf = 0;
  int maxcd = 0;
  double maxconq = -1;
  for (int i1 = 0; i1 <= 30; i1++) {
    for (int i2 = 0; i2 <= 30; i2++) {
      if (i1 != 0 || i2 != 0) {
        for (int i3 = 0; i3 <= 3000; i3++) {
          if ((i1 * a + i2 * b) * e >= i3 * c) {
            for (int i4 = 0; i4 <= 3000; i4++) {
              double conq =
                  ((double)i3 * c + i4 * d) /
                  (100.0 * i1 * a + 100.0 * i2 * b + (double)i3 * c + i4 * d);
              if (100 * i1 * a + 100 * i2 * b + i3 * c + i4 * d <= f &&
                  (i1 * a + i2 * b) * e >= i3 * c + i4 * d) {
                if (maxconq < conq) {
                  maxconq = conq;
                  maxf = 100 * i1 * a + 100 * i2 * b + i3 * c + i4 * d;
                  maxcd = i3 * c + i4 * d;
                }
              }
            }
          }
        }
      }
    }
  }
  cout << maxf << " " << maxcd << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  int maxf = 0;
  int maxcd = 0;
  double maxconq = -1;
  for (int i1 = 0; i1 <= 30; i1++) {
    if (i1 * a * 100 <= f) {
      for (int i2 = 0; i2 <= 30; i2++) {
        if (i1 != 0 || i2 != 0) {
          for (int i3 = 0; i3 <= 3000; i3++) {
            if ((i1 * a + i2 * b) * e >= i3 * c) {
              for (int i4 = 0; i4 <= 3000; i4++) {
                double conq =
                    ((double)i3 * c + i4 * d) /
                    (100.0 * i1 * a + 100.0 * i2 * b + (double)i3 * c + i4 * d);
                if (100 * i1 * a + 100 * i2 * b + i3 * c + i4 * d <= f &&
                    (i1 * a + i2 * b) * e >= i3 * c + i4 * d) {
                  if (maxconq < conq) {
                    maxconq = conq;
                    maxf = 100 * i1 * a + 100 * i2 * b + i3 * c + i4 * d;
                    maxcd = i3 * c + i4 * d;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << maxf << " " << maxcd << endl;
}
Problem p03599 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
double concentration(int sugar, int water) {
  double ds = (double)sugar;
  double dw = (double)water;
  return ds / (ds + dw);
}
int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  int max_a = F / 100 * A;
  int max_b = F / 100 * B;
  int max_c = F / C;
  int max_d = F / D;
  double con_e = concentration(E, 100);
  double max_con = -0.5;
  int max_water = 0;
  int max_sugar = 0;
  for (int i = 0; i < max_a; i++) {
    for (int j = 0; j < max_b; j++) {
      for (int k = 0; k < max_c; k++) {
        for (int l = 0; l < max_d; l++) {
          // i = 0, 1, 2, ..., max_a - 1;
          int water_a = 100 * A * i;
          int water_b = 100 * B * j;
          int sugar_c = C * k;
          int sugar_d = D * l;
          int all_mass = water_a + water_b + sugar_c + sugar_d;
          double all_con =
              concentration((sugar_c + sugar_d), (water_a + water_b));
          if (all_mass <= F) {
            if (all_con <= con_e) {
              if (all_con > max_con) {
                max_con = all_con;
                max_water = water_a + water_b;
                max_sugar = sugar_c + sugar_d;
              }
            }
          }
        }
      }
    }
  }
  cout << max_water + max_sugar << " " << max_sugar << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
double concentration(int sugar, int water) {
  double ds = (double)sugar;
  double dw = (double)water;
  return ds / (ds + dw);
}
int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  int max_a = F / 100 * A;
  int max_b = F / 100 * B;
  int max_c = F / C;
  int max_d = F / D;
  double con_e = concentration(E, 100);
  double max_con = -0.5;
  int max_water = 0;
  int max_sugar = 0;
  for (int i = 0; A * i * 100 <= F; i++) {
    int weight1 = A * i * 100;
    for (int j = 0; weight1 + B * j * 100 <= F; j++) {
      int weight2 = weight1 + B * j * 100;
      for (int k = 0; weight2 + C * k <= F; k++) {
        int weight3 = weight2 + C * k;
        for (int l = 0; weight3 + D * l <= F; l++) {
          // i = 0, 1, 2, ..., max_a - 1;
          int water_a = 100 * A * i;
          int water_b = 100 * B * j;
          int sugar_c = C * k;
          int sugar_d = D * l;
          int all_mass = water_a + water_b + sugar_c + sugar_d;
          double all_con =
              concentration((sugar_c + sugar_d), (water_a + water_b));
          if (all_mass <= F) {
            if (all_con <= con_e) {
              if (all_con > max_con) {
                max_con = all_con;
                max_water = water_a + water_b;
                max_sugar = sugar_c + sugar_d;
              }
            }
          }
        }
      }
    }
  }
  cout << max_water + max_sugar << " " << max_sugar << endl;
}
Problem p03599 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define rep(X, N) for (ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair

using namespace std;

int main() {

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  vector<int> water;
  vector<int> sugar;

  map<int, int> wm;
  map<int, int> sm;

  queue<int> tmpq;

  tmpq.push(0);

  while (!tmpq.empty()) {
    int tmp = tmpq.front();

    if (wm[tmp] == 0 && tmp <= f) {
      wm[tmp] = 1;
      water.pback(tmp);
      tmpq.push(tmp + a * 100);
      tmpq.push(tmp + b * 100);
    }

    tmpq.pop();
  }

  tmpq.push(0);

  while (!tmpq.empty()) {
    int tmp = tmpq.front();

    if (sm[tmp] == 0 && tmp <= f) {
      sm[tmp] = 1;
      sugar.pback(tmp);
      tmpq.push(tmp + c);
      tmpq.push(tmp + d);
    }

    tmpq.pop();
  }

  float p = 0;
  int bestw = 0;
  int bests = 0;
  ;

  rep(i, water.size()) {
    rep(j, sugar.size()) {
      int tmpw = water[i];
      int tmps = sugar[j];

      if (tmpw == 0 || tmpw + tmps > f || 100.0 * tmps / tmpw > 1.0 * e)
        continue;

      if (p < 100.0 * tmps / (tmpw + tmps)) {
        bestw = tmpw;
        bests = tmps;
        p = 100.0 * tmps / (tmpw + tmps);
      }
    }
  }

  assert(bestw != 0);

  cout << bestw + bests << " " << bests << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define rep(X, N) for (ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair

using namespace std;

int main() {

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  vector<int> water;
  vector<int> sugar;

  map<int, int> wm;
  map<int, int> sm;

  queue<int> tmpq;

  tmpq.push(0);

  while (!tmpq.empty()) {
    int tmp = tmpq.front();

    if (wm[tmp] == 0 && tmp <= f) {
      wm[tmp] = 1;
      water.pback(tmp);
      tmpq.push(tmp + a * 100);
      tmpq.push(tmp + b * 100);
    }

    tmpq.pop();
  }

  tmpq.push(0);

  while (!tmpq.empty()) {
    int tmp = tmpq.front();

    if (sm[tmp] == 0 && tmp <= f) {
      sm[tmp] = 1;
      sugar.pback(tmp);
      tmpq.push(tmp + c);
      tmpq.push(tmp + d);
    }

    tmpq.pop();
  }

  float p = 0;
  int bestw = 0;
  int bests = 0;
  ;

  rep(i, water.size()) {
    rep(j, sugar.size()) {
      int tmpw = water[i];
      int tmps = sugar[j];

      if (tmpw == 0 || tmpw + tmps > f || 100.0 * tmps / tmpw > 1.0 * e)
        continue;

      if (p < 100.0 * tmps / (tmpw + tmps)) {
        bestw = tmpw;
        bests = tmps;
        p = 100.0 * tmps / (tmpw + tmps);
      }
    }
  }

  if (bestw == 0) {
    bestw = water[1];
  }

  cout << bestw + bests << " " << bests << endl;

  return 0;
}