Error on 2nd Test Case

I was attempting to solve the CodeForces problem Problem 1555B and passed the first test case but not the second test case. I’ve tried many test cases I’ve made myself and my code seems to be working for all of them. I’m not sure which corner case I missed or if I went wrong in my code somewhere.

My code is

#include <iostream>
#include <algorithm>
#include <iostream>
#include <vector>

#define X first
#define Y second

#define W first
#define H second

#define D first
#define U second
#define L first
#define R second

using namespace std;

void solve() {
  pair<long long, long long> con;
  cin >> con.W >> con.H;

  pair<long long, long long> bl, ur;
  cin >> bl.X >> bl.Y >> ur.X >> ur.Y;

  pair<long long, long long> nrec;
  cin >> nrec.W >> nrec.H;

  pair<long long, long long> vcount = { 0, 0 };

  pair<long long, long long> hcount = { 0, 0 };

  if (nrec.H + ur.Y - bl.Y > con.H && nrec.W + ur.X - bl.X > con.W) {
    cout << -1 << "\n";
    return;
  }

  // check possible fits
  // top right
  if (con.H - ur.Y >= nrec.H || con.W - ur.X >= nrec.W) {
    cout << 0 << "\n";
    return;
  }
  // bottom left
  if (bl.X >= nrec.W || bl.Y >= nrec.H) {
    cout << 0 << "\n";
    return;
  }

  

  vcount.D = (con.H - nrec.H) - (con.H - ur.Y);
  if (bl.Y - vcount.D < 0 || !(nrec.W <= bl.X || con.H - nrec.H >= ur.Y - vcount.D)) {
    vcount.D = 1000000001;
  }
  hcount.R = nrec.W - bl.X;
  if (ur.X + hcount.R > con.W || !(nrec.W <= bl.X + hcount.R || con.H - nrec.H >= ur.Y)) {
    hcount.R = 1000000001;
  }
  vcount.U = nrec.H - bl.Y;
  if (ur.Y + vcount.U > con.H || !(nrec.H <= bl.Y + vcount.U || con.W - nrec.W >= ur.X)) {
    vcount.U = 1000000001;
  }
  hcount.L = (con.W - nrec.W) - (con.W - ur.X);
  if (bl.X - hcount.L < 0 || !(nrec.H <= bl.Y || con.W - nrec.W >= ur.X - hcount.L)) {
    hcount.L = 1000000001;
  }

  cout << min(min(vcount.D, vcount.U), min(hcount.L, hcount.R)) << "\n";
  return;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  // freopen("twotables.in", "r", stdin);

  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }

  return 0;
}

Also, I’m new to the forum, so if I did anything wrong while posting this, please tell me.

I take it the second test case is too large to debug by hand?

Yes, it was.

Thank you for your reply but I have solved it now :slight_smile: .

Nice! What was the bug?