Submission #560217

#TimeUsernameProblemLanguageResultExecution timeMemory
560217wenqiCoin Collecting (JOI19_ho_t4)C++17
100 / 100
60 ms3728 KiB
// trans rights #include <bits/extc++.h> using namespace std; using ll = long long; using ull = unsigned long long; int N; int A[100005]; int B[100005]; int main(int argc, const char *argv[]) { ios::sync_with_stdio(false); cin.tie(0); cin >> N; ll ans = 0; for (int k = 0; k < 2 * N; k++) { int x, y; cin >> x >> y; int fx = min(N, max(1, x)); ans += abs(x - fx); if (y <= 1) { A[fx]++; ans += abs(y - 1); }else { B[fx]++; ans += abs(y - 2); } } #ifdef DEBUG cerr << ans << '\n'; #endif for (int i = 1; i <= N; i++) { ans += abs(A[i - 1]) + abs(B[i - 1]); A[i] += A[i - 1] - 1; B[i] += B[i - 1] - 1; int u = min(abs(A[i]), abs(B[i])); if ((A[i] > 0) != (B[i] > 0)) { if (A[i] > 0) { A[i] -= u; B[i] += u; }else{ A[i] += u; B[i] -= u; } ans += u; } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...