This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
int n;
cin >> n;
vector<ll> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
ll S = b[0], mn = a[0], mx = a[0];
for (int i = 1; i < n; i++)
{
ll newMn = min(mn, a[i]), newMx = max(mx, a[i]);
if (S + b[i] - (newMx - newMn) > S - (mx - mn))
S += b[i], mn = newMn, mx = newMx;
}
cout << S - (mx - mn) << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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... |