The Bachelor's Problem

Jony lives in a “Bachelor’s house” with some of his friends. You may assume it as a hostel but it do…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#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??