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<vector>
#include<algorithm>
using namespace std;
using ll = long long;
struct art
{
ll sz,v;
art(ll &a,ll &b) : sz(a),v(b) {};
bool operator <(const art &other) const
{
return sz < other.sz;
}
};
int main()
{
vector<art> arta; int n; ll a,b; cin >> n;
for(int i = 1; i <= n ; i++)
{
cin >> a >> b;
arta.push_back(art(a,b));
}
sort(arta.begin(),arta.end()); ll suma = arta[0].v;
ll minim = -arta[0].sz,ans = -1e18,last = suma;
for(int i = 1; i < n ; i++)
{
suma += arta[i].v;
ans = max(ans,suma - arta[i].sz - minim);
minim = min(minim,last - arta[i].sz);
last = suma;
}
cout << ans;
}
# | 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... |