제출 #875948

#제출 시각아이디문제언어결과실행 시간메모리
875948misu2005Art Exhibition (JOI18_art)C++11
0 / 100
1 ms2392 KiB
#include <iostream> #include <algorithm> #include <climits> using namespace std; struct ceva { long long sz, val; } v[500002]; bool cmp(ceva x, ceva y) { return x.sz < y.sz; } int n; long long sp[500002], tree[2000005]; void build(int node, int st, int dr) { if (st == dr) { tree[node] = sp[st] - v[st].sz; return ; } int mij = (st + dr)/2; build(2*node, st, mij); build(2*node+1, mij+1, dr); tree[node] = max(tree[2*node], tree[2*node+1]); } int query(int node, int st, int dr, int left, int right) { if (left <= st and dr <= right) { return tree[node]; } int mij = (st + dr)/2; long long ans1 = LLONG_MIN, ans2 = LLONG_MIN; if (left <= mij) ans1 = query(2*node, st, mij, left, right); if (mij < right) ans2 = query(2*node+1, mij+1, dr, left, right); return max(ans1, ans2); } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> v[i].sz >> v[i].val; } sort(v+1, v+n+1, cmp); for (int i = 1; i <= n; i++) { sp[i] = sp[i-1] + v[i].val; } build(1, 1, n); long long maxim = LLONG_MIN; for (int i = 1; i <= n; i++) { long long x = sp[i-1] - v[i].sz; long long rezdr = query(1, 1, n, i, n); maxim = max(maxim, rezdr-x); } cout << maxim; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...