What is wrong with my code ?? I have been struggling with this for so long.
Can anyone help me debug this code ??
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
vector<int> v;
for (int i = a; i <= b; i++) {
v.push_back(i);
}
sort(v.begin(), v.end());
int m = v.size() / 2;
int c = v[m];
cout << c << endl;
}
}
Can you help me what is wrong ???
I first push all values from a to b in a vector then I sort the vector to greedily select the median value.
Why is my logic wrong ?
PS: If you are ratist and here to just downvote me, Mike please ban such people.
wtf are you doing
I think you've misread the question, you are given 2 numbers and the equation : min{(c-a)+(b-c)} where (a≤c≤b) ,if you look closely the equation is min(b-a) which is a constant 'b-a' so thats it.
but how is my code WA my logic is also right ?
nope, its totally different from the actual apporach.
I mean, you just have to return (c-a)+(b-c), which equals (b-a).
cout << "Jesus Christ" << endl;
Jesus Christ is the answer to everything. I get that you're a newbie, but how do you not even know this?