This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++17 -D_GLIBCXX_DEBUG art.cpp -oart && ./art " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fv(i,v) f(i,sz(v))
struct S{ int a,b; };
main(){
ios::sync_with_stdio(0),cin.tie(0);
int n;
cin>>n;
vc<S> art(n);
f(i,n) cin>>art[i].a>>art[i].b;
sort(all(art),[](S x,S y){ return x.a>y.a; });
vc<int> p(n+1);
f(i,n) p[i+1]=p[i]+art[i].b;
int best=0;
int low=art[0].a;
f(i,n+1){
if(i) best=max(best,p[i]+art[i-1].a-low);
if(i<n) low=min(low,p[i]+art[i].a);
}
cout<<best<<'\n';
}
Compilation message (stderr)
art.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main(){
| ^~~~
# | 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... |