Help me solve this Div3 A

Revision en1, by StellarSpecter, 2024-09-12 18:02:14

2009A - Minimize!

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 ?

Tags help, please

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English StellarSpecter 2024-09-12 18:02:14 795 Initial revision (published)