Pagini recente » Cod sursa (job #3204750) | Cod sursa (job #2621940) | Cod sursa (job #564598) | Cod sursa (job #194872) | Cod sursa (job #2932714)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("tribute.in");
ofstream fout("tribute.out");
int n, dx, dy;
vector<pair<int,int>>coord;
inline int distManhX()
{
int ans = 0;
int st = 0, dr = coord.size()-1;
while(st < dr && coord[dr].first - coord[st].first > dx)
{
ans += coord[dr].first - coord[st].first - dx;
st++;
dr--;
}
return ans;
}
inline int distManhY()
{
int ans = 0;
int st = 0, dr = coord.size()-1;
while(st < dr && coord[dr].second - coord[st].second > dy)
{
ans += coord[dr].second - coord[st].second - dy;
st++;
dr--;
}
return ans;
}
inline bool comp(pair<int,int>x, pair<int,int>y)
{
if(x.first == y.first)
return x.second < y.second;
return x.first < y.first;
}
inline void solve()
{
sort(coord.begin(), coord.end(), comp);
fout << distManhX() + distManhY();
}
int main()
{
fin >> n >> dx >> dy;
for(int i=1;i<=n;++i)
{
int x, y;
fin >> x >> y;
coord.push_back({x,y});
}
solve();
}