# Need help with solving a problem

Hi,
I was doing a problem on a contest website that is linked by USACO guide. Problem - C - Codeforces
And when I submit my solution, it keeps saying that I failed test case 8. I’m stuck on this and couln’t figure out the right solution. Some help would be greatly appreciated. Thanks!

Here’s my code in Java:

import java.io.;
import java.util.
;

public class WhiteSheet {

``````public static void main(String[] args) throws IOException {

int x1 = Integer.parseInt(st.nextToken()); // whitesheet
int y1 = Integer.parseInt(st.nextToken());
int x2 = Integer.parseInt(st.nextToken());
int y2 = Integer.parseInt(st.nextToken());
int x3 = Integer.parseInt(st.nextToken()); // blacksheet
int y3 = Integer.parseInt(st.nextToken());
int x4 = Integer.parseInt(st.nextToken());
int y4 = Integer.parseInt(st.nextToken());
int x5 = Integer.parseInt(st.nextToken()); // blacksheet
int y5 = Integer.parseInt(st.nextToken());
int x6 = Integer.parseInt(st.nextToken());
int y6 = Integer.parseInt(st.nextToken());

int area = (x2-x1) * (y2-y1);
int o1 = getOverlap(x1,y1,x2,y2,x3,y3,x4,y4);
int o2 = getOverlap(x1,y1,x2,y2,x5,y5,x6,y6);
int inter = getOverlap(x3,y3,x4,y4,x5,y5,x6,y6);

if (area > o1+o2-inter) {
System.out.print("YES");
}else {
System.out.print("NO");
}

}

public static int getOverlap(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4) {
int lx = Math.max(x1, x3);
int ux = Math.min(x2, x4);
int ly = Math.max(y1, y3);
int uy = Math.min(y2, y4);

if (lx > ux || ly > uy) {
return 0;
}

return (ux-lx) * (uy-ly);
}
``````

}

1 Like