Cod sursa(job #2900610)

Utilizator iancupoppPopp Iancu Alexandru iancupopp Data 11 mai 2022 15:36:17
Problema Tribute Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 5e4 + 5;

long long calc(vector<int>& v, const int d) {
  long long ans = 0;
  int st = 0, dr = v.size() - 1;
  sort(v.begin(), v.end());
  while (v[dr] - v[st] > d) {
    ans += v[dr] - v[st] - d;
    ++st, --dr;
  }
  return ans;
}

int main() {
  ifstream cin("tribute.in");
  ofstream cout("tribute.out");
  int n, dx, dy;
  vector<int> a, b;
  cin >> n >> dx >> dy;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }
  cin.close();
  cout << calc(a, dx) + calc(b, dy) << "\n";
  cout.close();
  return 0;
}