Cod sursa(job #3234569)

Utilizator rockoanaOana Pasca rockoana Data 10 iunie 2024 00:45:05
Problema Inundatii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
using i64 = int64_t;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // #ifdef LOCAL
  ifstream cin{"inundatii.in"};
  ofstream cout{"inundatii.out"};
  // ifstream cin{"input.txt"};
  // ofstream cout{"output.txt"};
  //  #endif

  i64 n;
  cin >> n;

  vector<vector<i64>> v(3, vector<i64>(n));
  for (i64 i = 0; i < n; i++) {
    cin >> v[0][i] >> v[1][i] >> v[2][i];
    // v[0][i] -= i, v[1][i] -= i, v[2][i] -= i;
  }

  i64 res = 0;
  for (i64 i = 0; i < 3; i++) {
    i64 med = v[i][n / 2];
    if (n % 2 == 1 && n != 1) {
      med = v[i][n / 2 + n % 2];
    }
    for (i64 j = 0; j < n; j++) {
      res += abs(med - (v[i][j] - j));
    }
  }

  cout << res << endl;

  return 0;
}