Submission #1133987

#TimeUsernameProblemLanguageResultExecution timeMemory
1133987antonnCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> #define F first #define S second using namespace std; using ll = long long; using pi = pair<int, int>; using vi = vector<int>; template<class T> bool ckmin(T& a, T b) { return b < a ? a = b, true : false; } template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, true : false; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pi> a(2 * n + 1); for (int i = 1; i <= 2 * n; ++i) cin >> a[i].F >> a[i].S; sort(a.begin() + 1, a.end()); ll ans = 0; for (int i = 1; i <= 2 * n; ++i) ans += abs(a[i].F - (i + 1) / 2); sort(a.begin() + 1, a.end(), [&](pi a, pi b) { return a.S < b.S; }); for (int i = 1; i <= 2 * n; ++i) ans += abs(a[i].S - (i <= n ? 1 : 2)); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...