이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& _old, T _new) { return _old > _new && (_old = _new, true); }
template <class T>
bool chmax(T& _old, T _new) { return _old < _new && (_old = _new, true); }
constexpr int64_t INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
class binary_indexed_tree {
const size_t n;
vector<T> tree;
public:
binary_indexed_tree(size_t n) : n(n), tree(n + 1, ~INF) {}
void update(size_t i, T val) {
for (++i; i <= n; i += i & -i)
chmax(tree[i], val);
}
T query(size_t i) const {
T ret = ~INF;
for (; i; i &= i - 1)
chmax(ret, tree[i]);
return ret;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n;
cin >> n;
vector<pair<int64_t, int64_t>> a(n);
for (auto& [x, y] : a) {
cin >> x >> y;
}
sort(a.begin(), a.end(), [&](const auto& lhs, const auto& rhs) {
return lhs.first < rhs.first;
});
vector<int64_t> pref(n + 1);
for (int i = 0; i < n; ++i) {
pref[i + 1] = pref[i] + a[i].second;
}
binary_indexed_tree<int64_t> bit(n);
for (int i = 0; i < n; ++i) {
bit.update(i, a[i].first - pref[i]);
}
int64_t ans = ~INF;
for (int r = 1; r < n; ++r) {
chmax(ans, pref[r] - a[r - 1].first + bit.query(r));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |