My issue
so i was able to figure out 2*m+1 would be able to solve the question but after much wrong submission, why this didn’t work?
#include <iostream>
#include<cmath>
using namespace std;
int minimalPeopleToAsk(int n, int m) {
int total = n+m;
int half = (total+1)/2;
if(n>=half){
// think
int x = half-m;
if(x>m) return half;
else{
return 2*m+1;
}
}
else return -1;
}
int main() {
// your code goes here
int t; cin>>t;
while(t--){
int n, m; cin>>n>>m;
int result = minimalPeopleToAsk(n,m);
cout<<result<<endl;
}
return 0;
}
### My code
include
include
using namespace std;
int minimalPeopleToAsk(int n, int m) {
if(n<=m) return -1;
else return 2*m+1;
}
int main() {
// your code goes here
int t; cin>>t;
while(t–){
int n, m; cin>>n>>m;
int result = minimalPeopleToAsk(n,m);
cout<<result<<endl;
}
return 0;
}
Problem Link: Truth Teller And Liars 101 Practice Coding Problem
Blockquote