Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int feasiblePoint(int N, vector<vector<int>> &A)
- {
- vector<int> X(N);
- vector<int> Y(N);
- for(int i=0;i<N;i++){
- X[i] = A[i][0];
- Y[i] = A[i][1];
- }
- sort(X.begin(),X.end());
- sort(Y.begin(),Y.end());
- int mid_ele = N/2; // Since the value of N odd, there is only one middle element.
- int sum =0;
- for(int i=0;i<N;i++){
- sum+=(abs(X[i] - X[mid_ele]));
- sum+=(abs(Y[i] - Y[mid_ele]));
- }
- return sum;
- }
- int main()
- {
- int N;
- cin>>N;
- vector<vector<int>> A(N);
- for(int i=0;i<N;i++){
- int x,y;
- cin>>x>>y;
- A[i].push_back(x);
- A[i].push_back(y);
- }
- cout<<feasiblePoint(N,A)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment