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;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
int64_t cost = 0;
vector<vector<int> > coins(N,vector<int>(2));
for(int i=0;i<2*N;i++){
int X,Y;
cin >> X >> Y;
if(X > N) cost += X-N;
else if(X < 1) cost += 1-X;
if(Y > 2) cost += Y-2;
else if(Y < 1) cost += 1-Y;
X = min(N,max(1,X));
Y = min(2,max(1,Y));
coins[X-1][Y-1]++;
}
int more[] = {0,0};
for(int i=0;i<N;i++){
more[0] += coins[i][0] - 1;
more[1] += coins[i][1] - 1;
if(more[0] < 0){
int temp = min(-more[0],max(0,more[1]));
cost += temp;
more[0] += temp;
more[1] -= temp;
}
if(more[1] < 0){
int temp = min(-more[1],max(0,more[0]));
cost += temp;
more[1] += temp;
more[0] -= temp;
}
cost += abs(more[0]) + abs(more[1]);
}
cout << cost << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |