# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331766 | daniel920712 | Art Exhibition (JOI18_art) | C++14 | 241 ms | 24832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
struct A
{
long long x,y;
}all[500005];
long long add[500005]={0};
bool F(A a,A b)
{
return a.x<b.x;
}
int main()
{
long long N,ans=0,i,j,big=-1e18;
scanf("%lld",&N);
for(i=0;i<N;i++) scanf("%lld %lld",&all[i].x,&all[i].y);
sort(all,all+N,F);
for(i=0;i<N;i++) add[i+1]=add[i]+all[i].y;
for(i=N-1;i>=0;i--)
{
big=max(big,add[i+1]-all[i].x);
ans=max(ans,all[i].x-add[i]+big);
//printf("%lld %lld\n",i,big);
}
/*for(i=0;i<N;i++)
{
for(j=i;j<N;j++)
{
//printf("%lld %lld %lld %lld\n",i,j,)
ans=max(ans,add[j+1]-add[i]-(all[j].x-all[i].x));
}
}*/
printf("%lld\n",ans);
return 0;
}
Compilation message (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... |