이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
using namespace std;
int n, ans = 0;
pair <int, int> pr[5002];
void solve(int i, int j)
{
if (i == n || j == n)
return;
int tot = pr[i].second;
if (j != 0)
tot -= pr[j-1].second;
ans = max(ans, tot - (pr[i].first-pr[j].first));
if (i+1 < n)
solve(i+1, j);
if (j+1 <= i)
solve(i, j+1);
}
signed main()
{
IOS;
cin >> n;
pr[0].first = pr[0].second = 0;
for (int i = 1; i <= n; i++)
cin >> pr[i].first >> pr[i].second;
sort(pr, pr+n+1);
for (int i = 1; i <= n; i++)
pr[i].second += pr[i-1].second;
solve(0, 0);
cout << ans;
return 0;
}
# | 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... |