이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> trio;
typedef pair<ll,ll> pii;
const int MAXN = 2e5+10;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<pii> v(n);
for(int i = 0; i < n; i++)
cin >> v[i].fr >> v[i].sc;
sort(all(v));
ll sum = 0, at = -LINF, ans = 0;
for(int i = 0; i < n; i++) {
at = max(at, v[i].fr - sum);
sum += v[i].sc;
ans = max(ans, - v[i].fr + sum + at);
}
cout << ans << "\n";
}
# | 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... |