# The Bachelor's Problem

Limits: 2s, 512 MB

Jony lives in a “Bachelor’s house” with some of his friends. You may assume it as a hostel but it doesn’t operate as a hostel. To lead a life in a hostel is so much tough. They have to pay so many different bills in every month along with everyday marketing. There is a manager to whom everyone pays their bills in advance every month. There are six types of bills they have to pay, like House Rent, Meal, Internet Bill, Maid Bill, Electricity Bill, and Garbage Bill. As Jony has to pay all of his bills in advance so he has to fix a budget for him every month. He always gets confused to determine his budget as there are some issues. Help him out!

This is a companion discussion topic for the original entry at https://toph.co/p/the-bachelors-problem
``````#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n,b,m,i,cmb=0,nmb=0;
cin>>t;
for(i=1;i<=t;i++){
for(int j=1;j<=6;j++){
cin>>n;
cmb=cmb+n;
}
cin>>b;
for(int k=1;k<=6;k++){
cin>>m;
nmb=nmb+m;
}
if(b>=cmb){
cout<<"Case "<<i<<": "<<nmb-(b-cmb)<<endl;
}
else{
cout<<"Case "<<i<<": "<<nmb+(cmb-b)<<endl;
}
cmb=0;
nmb=0;
}
return 0;
}
``````

what is the issue?

Consider the case first month budget is enough for both first and second month.

1 Like

import java.util.Scanner;
public class aa {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int t=x.nextInt();
for(int i=1;i<=t;i++) {
int n1=x.nextInt();
int n2=x.nextInt();
int n3=x.nextInt();
int n4=x.nextInt();
int n5=x.nextInt();
int n6=x.nextInt();
int sum1=n1+n2+n3+n4+n5+n6;
int b=x.nextInt();
int m1=x.nextInt();
int m2=x.nextInt();
int m3=x.nextInt();
int m4=x.nextInt();
int m5=x.nextInt();
int m6=x.nextInt();
int sum2=m1+m2+m3+m4+m5+m6;
int ans=sum2-(b-sum1);
if(ans>=0) {

``````		System.out.printf("Case %d: %d",i,ans);

}
else if(ans<0){
System.out.printf("Case %d: 0",i);
}
}

}
``````

}
***what’s the problem in the cord??