Submission #153397

#TimeUsernameProblemLanguageResultExecution timeMemory
153397mhy908Art Exhibition (JOI18_art)C++14
100 / 100
396 ms41292 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define llinf 987654321987654321 using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; struct SEGMENT_TREE { struct NODE { int st, fin; LL maxx; } tree[3000000]; int x=0; void maketree(int point, int num) { if(num==1) { x++; tree[point].st=tree[point].fin=x; } if(num<=1)return; maketree(point*2, num-num/2); maketree(point*2+1, num/2); tree[point].st=tree[point*2].st; tree[point].fin=tree[point*2+1].fin; } LL maxrange(int a, int b, int point) { if(tree[point].st>=a&&tree[point].fin<=b)return tree[point].maxx; if(tree[point].st>b||tree[point].fin<a)return -llinf; return max(maxrange(a, b, point*2), maxrange(a, b, point*2+1)); } void updaterange(int point, int num, LL p) { if(tree[point].st==tree[point].fin) { tree[point].maxx=p; return; } if(num<=tree[point*2].fin)updaterange(point*2, num, p); else updaterange(point*2+1, num, p); tree[point].maxx=max(tree[point*2].maxx, tree[point*2+1].maxx); } void init(int n) { maketree(1, n); } LL get_max(int a, int b) { return maxrange(a, b, 1); } void update(int a, LL num) { updaterange(1, a, num); } }seg; int n; pll arr[500010]; LL sum[500010], ans; int main() { scanf("%d", &n); seg.init(n); for(int i=1; i<=n; i++){ scanf("%lld %lld", &arr[i].F, &arr[i].S); } sort(arr+1, arr+n+1); for(int i=1; i<=n; i++) sum[i]=sum[i-1]+arr[i].S; for(int i=1; i<=n; i++) seg.update(i, sum[i]-arr[i].F); for(int i=1; i<=n; i++) ans=max(ans, seg.get_max(i, n)+arr[i].F-sum[i-1]); printf("%lld", ans); }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
art.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &arr[i].F, &arr[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...