이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
using namespace std;
const int maxn = 2e5 + 11;
int n;
pair<ll, ll>p[maxn + 3];
ll sum[maxn + 3];
bool cmp(pll a, pll b)
{
if(a.fi == b.fi) return a.se > b.se;
return a.fi < b.fi;
}
int main()
{
// freopen("ARTEXHIBITION.INP", "r", stdin);
//freopen("ARTEXHIBITION.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> p[i].first >> p[i].second;
}
sort(p + 1, p + n + 1, cmp);
ll ans = 0;
for(int i = n - 1; i >= 1; i--)
{
if(p[i + 1].se >= p[i + 1].fi - p[i].fi)
{
p[i].se = p[i].se + p[i + 1].se - p[i + 1].fi + p[i].fi;
}
ans = max(ans, p[i].se);
//cout << p[i].first << ' ' << p[i].second << '\n';
}
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... |