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>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
using namespace std;
const int maxn = 2e5 + 11;
int n;
pair<ll, ll>p[maxn + 3];
ll sum[maxn + 3];
bool cmp(pll a, pll b)
{
if(a.fi == b.fi) return a.se > b.se;
return a.fi < b.fi;
}
int main()
{
// freopen("ARTEXHIBITION.INP", "r", stdin);
//freopen("ARTEXHIBITION.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> p[i].first >> p[i].second;
}
sort(p + 1, p + n + 1, cmp);
ll ans = 0;
for(int i = n - 1; i >= 1; i--)
{
if(p[i + 1].se >= p[i + 1].fi - p[i].fi)
{
p[i].se = p[i].se + p[i + 1].se - p[i + 1].fi + p[i].fi;
}
ans = max(ans, p[i].se);
//cout << p[i].first << ' ' << p[i].second << '\n';
}
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... |