#include <bits/stdc++.h>
using namespace std;
#define s second
#define ll long long
#define MAX 60 * 10000
void solve() {
ll n;
cin >> n;
vector <pair<ll,ll>> b(n);
for (ll i = 0; i < n; i++) {
cin >> b[i].first >> b[i].second;
} vector <ll> dp(n + 1);
dp[0] = 0;
ll s = 0ll;
ll max1 = b[0].first,min1 = b[0].first;
for (ll i = 1; i <= n; i++) {
if (dp[i - 1] >= (s + b[i - 1].s) - (max(b[i - 1].first,max1) - min(b[i - 1].first,min1))) {
dp[i] = dp[i - 1];
} else {
dp[i] = (s + b[i - 1].s) - (max(b[i - 1].first,max1) - min(b[i - 1].first,min1));
s += b[i - 1].s;
max1 = max(b[i - 1].first,max1);
min1 = min(b[i - 1].first,min1);
}
} cout << dp[n];
}
int main()
{
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |