이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define f first
#define pll pair <ll,ll>
#define pii pair <int,int>
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
using namespace std;
const int N = 5e5 + 5;
ll t[4*N],lz[4*N],p[N];
pll d[N];
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>>d[i].f>>d[i].s;
}
sort(d + 1,d + n + 1);
for (int i = 1; i <= n; i++){
p[i] = p[i - 1] + d[i].s;
}
ll ans = 0,mn = 1e18;
for (int i = 0; i <= n; i++){
ans = max(ans, p[i] - d[i].f - mn);
mn = min(mn, p[i] - d[i + 1].f);
}
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... |