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>
#define rep(i,x,n) for(int i=x; i<n; i++)
using namespace std;
int main() {
int N;
cin>>N;
vector<vector<int>> A(N);
rep(i, 0, N) {
int x, y;
cin>>x>>y; --y;
A[y].push_back(x);
}
long long s=0;
for(auto&v:A) {
int M=v.size();
sort(begin(v), end(v));
if(M>=2) {
s+=v[1]-v[0]+v[M-1]-v[M-2];
rep(i, 1, M-1) s+=min(v[i]-v[i-1], v[i+1]-v[i]);
}
}
cout<<s;
}
# | 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... |