Submission #943681

#TimeUsernameProblemLanguageResultExecution timeMemory
943681HiepVu217Palembang Bridges (APIO15_bridge)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 17; int k, n; long long s[N], ans, ls, rs; priority_queue <int> lpq, rpq; vector <pair <int, int>> vt; bool cmp (pair <int, int> x, pair <int, int> y) { return x.first + x.second < y.first + y.second; } void add (int x) { int mid; if (lpq.size()) { mid = lpq.top(); } else { mid = 1e9 + 17; } if (x <= mid) { lpq.push(x); ls += x; } else { rpq.push(-x); rs += x; } if (lpq.size() > rpq.size() + 1) { int t = lpq.top(); lpq.pop(); ls -= t; rpq.push(-t); rs += t; } if (rpq.size() > lpq.size()) { int t = -rpq.top(); rpq.pop(); rs -= t; lpq.push(t); ls += t; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k >> n; long long z = 0; vt.push_back ({0, 0}); for (int i = 1; i <= n; ++i) { int a, b; char x, y; cin >> x >> a >> y >> b; if (x == y) { z += abs (a - b); continue; } vt.push_back ({a, b}); } sort (vt.begin(), vt.end(), cmp); n = vt.size() - 1; z += n; for (int i = 1; i <= n; ++i) { add (vt[i].first); add (vt[i].second); s[i] = rs - ls; } ans = s[n]; if (k == 2) { while (lpq.size()) { lpq.pop(); } while (rpq.size()) { rpq.pop(); } ls = rs = 0; for (int i = n; i > 0; i--) { add (vt[i].first); add (vt[i].second); ans = min (ans, rs - ls + pref[i - 1]); } } cout << ans + z; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:95:30: error: 'pref' was not declared in this scope
   95 |    ans = min (ans, rs - ls + pref[i - 1]);
      |                              ^~~~