이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pear=pair<ll, ll>;
#define fi first
#define se second
#define nl << '\n'
#define uk << ' '
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
cin.exceptions(cin.failbit);
ll n;
cin >> n;
ll i;
vector<pair<ll, ll>> art(n+1);
for(i=1; i<=n; i++){
cin >> art[i].fi >> art[i].se;
}
vector<ll> pre(n+1);
sort(art.begin()+1, art.end());
for(i=1; i<=n; i++){
pre[i]=pre[i-1]+art[i].se;
}
ll maxi=LLONG_MIN, ans=0;
for(i=1; i<=n; i++){
maxi=max(maxi, art[i].fi-pre[i-1]);
ans=max(ans, pre[i]-art[i].fi+maxi);
}
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... |