# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1201474 | nguyn | Coin Collecting (JOI19_ho_t4) | C++20 | 0 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int x[N], y[N], n;
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n;
for (int i = 1; i <= 2 * n; i++) {
cin >> x[i] >> y[i];
}
sort(x + 1, x + 1 + 2 * n);
ll res = 0;
int cnt = 0;
for (int i = 1; i <= 2 * n; i++) {
if (y[i] > 2) {
res += y[i] - 2;
y[i] = 2;
}
if (y[i] < 1) {
res += 1 - y[i];
y[i] = 1;
}
if (y[i] == 2) cnt++;
}
if (cnt < n) cnt = 2 * n - cnt;
res += cnt - n;
// cout << res;
for (int i = 1; i <= 2 * n; i++) {
int cur = (i + 1) / 2;
res += llabs(x[i] - cur);
}
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |