# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1265083 | ducdev | Art Exhibition (JOI18_art) | C++17 | 0 ms | 320 KiB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 5e5;
const int MOD = 1e9 + 7;
int n;
int comp[MAX_N + 5];
ll bit[MAX_N + 5];
pair<ll, int> a[MAX_N + 5];
void update(int pos, ll val) {
for (; pos <= n; pos += pos & (-pos))
bit[pos] = min(bit[pos], val);
};
ll get(int pos) {
ll ret = 1e18;
for (; pos > 0; pos -= pos & (-pos))
ret = min(ret, bit[pos]);
return ret;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> n;
vector<pair<ll, int>> v(n);
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
v[i - 1] = make_pair(a[i].first, i);
bit[i] = 1e18;
};
sort(v.begin(), v.end());
int cur = 0;
for (int i = 0; i < n; i++) {
cur += (i == 0 || v[i - 1].first != v[i].first);
comp[v[i].second] = cur;
};
sort(a + 1, a + n + 1);
ll pref = 0, res = 0;
for (int i = 1; i <= n; i++) {
pref += a[i].second;
res = max(res, (pref - a[i].first) - get(comp[i]));
res = max(res, pref - a[i].first + a[1].first);
update(comp[i], pref - a[i].second - a[i].first);
};
cout << res << '\n';
};
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |