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 <bits/stdc++.h>
using namespace std;
#define taskname "JOI18_art"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front
template<typename TH>
void _dbg(const char* sdbg, TH h)
{
cerr << sdbg << " = " << h << "\n";
}
template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
while (*sdbg != ',') cerr << *sdbg++;
cerr << " = " << h << ",";
_dbg(sdbg + 1, t...);
}
#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";
const int N=5e5+5;
const int64_t LINF=1e18;
struct Data
{
int64_t a,b;
};
int n;
Data d[N];
int64_t s[N];
bool Cmp(Data x,Data y)
{
return x.a<y.a;
}
void Solve()
{
sort(d+1,d+1+n,Cmp);
forinc(i,1,n)
{
s[i]=s[i-1]+d[i].b;
}
int64_t maxVal=-LINF,ans=0;
fordec(l,n,1)
{
maxVal=max(maxVal,s[l]-d[l].a);
ans=max(ans,maxVal-s[l-1]+d[l].a);
}
cout<<ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
// freopen(taskname".INP","r",stdin);
#endif // ONLINE_JUDGE
cin>>n;
forinc(i,1,n)
{
cin>>d[i].a>>d[i].b;
}
Solve();
return 0;
}
# | 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... |