This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 5003;
vector<pair<int, int>> g[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 2; i <= n + m; ++i) {
int p, c;
cin >> p >> c;
g[p].emplace_back(i, c);
}
if (n == 1) {
long long ans = 1e15;
for (int i = 0; i < (int) g[1].size(); ++i) {
long long res = 0;
for (int j = 0; j < (int) g[1].size(); ++j) {
res += abs(g[1][i].second - g[1][j].second);
}
ans = min(ans, res);
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |