이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 123;
int n;
vector<pair<ll,ll>> a(N);
ll p[N];
//dp[i] = p[i] - p[j - 1] - (a[i] - a[j]) = p[i] - a[i] - (p[j - 1] - a[j])
//
void test(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i].first >> a[i].second;
}
sort(a.begin() + 1,a.begin() + n + 1);
ll vl = -a[1].first;
for(int i = 1;i <= n;i++){
p[i] = p[i - 1] + a[i].second;
}
ll res ;
for(int i = 1;i <= n;i++){
vl = min(vl,p[i - 1] - a[i].first);
if(i == 1) res = p[i] - a[i].first - vl;
else res = max(res,p[i] - a[i].first - vl);
}
cout << res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) test();
}
# | 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... |