Submission #1079443

#TimeUsernameProblemLanguageResultExecution timeMemory
1079443JooDdaeCoin Collecting (JOI19_ho_t4)C++17
100 / 100
39 ms7484 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, x[200200], y[200200], c[100100][2]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i=1;i<=n+n;i++) cin >> x[i] >> y[i]; ll ans = 0; for(int i=1;i<=n+n;i++) { int D = min(max(x[i], 1), n); ans += abs(D-x[i]); if(y[i] >= 2) { c[D][0]++; ans += y[i]-2; } else { c[D][1]++; ans += 1-y[i]; } } for(int i=1;i<=n;i++) { c[i][0] += c[i-1][0]-1; c[i][1] += c[i-1][1]-1; while(c[i][0] > 0 && c[i][1] < 0) c[i][0]--, c[i][1]++, ans++; while(c[i][1] > 0 && c[i][0] < 0) c[i][1]--, c[i][0]++, ans++; ans += abs(c[i][0]) + abs(c[i][1]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...