voidsolve(){ int n, m, d; std::cin >> n >> m >> d;
std::vector<int> a(n + 1); for (int i = 1;i <= n;i ++) { std::cin >> a[i]; }
i64 ans = 0, sum = 0; std::multiset<int> st; for (int i = 1;i <= n;i ++) { if (a[i] <= 0) continue; st.insert(a[i]); sum += a[i]; if (st.size() > m) { sum -= *st.begin(); st.erase(st.begin()); } ans = std::max(ans, sum - 1LL * i * d); }
int32_tmain(){ int q; cin >> q; while (q--) { int w, f, n; cin >> w >> f >> n; vector<int> s(n); int sum_s = 0; for (int i = 0; i < n; ++i) { cin >> s[i]; sum_s += s[i]; } vector<bool> dp(sum_s + 1); dp[0] = true; for (int i = 0; i < n; ++i) { for (int w = sum_s; w - s[i] >= 0; --w) { dp[w] = dp[w] || dp[w - s[i]]; } } int ans = 2e9; for (int i = 0; i <= sum_s; ++i) { if (dp[i]) { ans = min(ans, max((i + w - 1) / w, (sum_s - i + f - 1) / f)); } } cout << ans << "\n"; } return0; }
std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; }
std::multiset<int> s, d{0};
auto add = [&](int x) { auto it = s.insert(x); auto r = std::next(it); if (it != s.begin()) { d.insert(x - *std::prev(it)); } if (r != s.end()) { d.insert(*r - x); } if (it != s.begin() && r != s.end()) { d.extract(*r - *std::prev(it)); } };
auto del = [&](int x) { auto it = s.find(x); auto r = std::next(it); if (it != s.begin()) { d.extract(x - *std::prev(it)); } if (r != s.end()) { d.extract(*r - x); } if (it != s.begin() && r != s.end()) { d.insert(*r - *std::prev(it)); } s.erase(it); };
for (int i = 0; i < n; i++) { add(a[i]); }
int q; std::cin >> q; for (int i = 0; i < q; i++) { int x, y; std::cin >> x >> y; x--; del(a[x]); a[x] = y; add(a[x]); int ans = *s.rbegin() + *d.rbegin(); std::cout << ans << " \n"[i == q - 1]; } }