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 pair <long long,long long>
using namespace std;
ll a[5000002];
long long oo=100000000000000000;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i=1;i<=n;i++)
{
cin >> a[i].first >> a[i].second;
}
sort (a+1,a+1+n);
int i2=1;
long long tong=0;
long long kq=0-oo;
for (int i=1;i<=n;i++)
{
if (tong<a[i].first-a[i2].first)
{
tong=0;
i2=i;
}
tong=tong+a[i].second;
// while ((i2<i) and (a[i2+1].first-a[i2].first>a[i2].second))
// {
// tong=tong-a[i2].second;
// i2++;
// }
kq=max(kq,tong-(a[i].first-a[i2].first));
// cout << i << " " << i2 << " " << tong-(a[i].first-a[i2].first) << '\n';
}
cout << kq;
}
| # | 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... |