Pagini recente » Cod sursa (job #2425788) | 795353277152115sfs | Cod sursa (job #2145908) | Cod sursa (job #626475) | Cod sursa (job #1861986)
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAXN 220
using namespace std;
struct coord
{
int x, y;
bool operator()(coord e, coord f)
{
return e.x < f.x;
}
}a[MAXN];
int n, st[MAXN][MAXN], dr[MAXN][MAXN];
void update(int lo, int hi)
{
st[lo][hi] = min(2*a[lo].y + a[lo+1].x-a[lo].x + st[lo+1][hi], 2*a[hi].y+a[hi].x-a[lo].x+a[hi].x-a[hi-1].x + dr[lo][hi-1]);
dr[lo][hi] = min(2*a[hi].y + a[hi].x-a[hi-1].x + dr[lo][hi-1], 2*a[lo].y+a[hi].x-a[lo].x+a[lo+1].x-a[lo].x + st[lo+1][hi]);
for (int i = lo+1; i < hi; i++) {
st[lo][hi] = min(st[lo][hi], a[i].x - a[lo].x + 2*a[i].y + max(a[i].x-a[i-1].x + dr[lo][i-1], a[i+1].x-a[i].x + st[i+1][hi]));
dr[lo][hi] = min(dr[lo][hi], a[hi].x - a[i].x + 2*a[i].y + max(a[i].x-a[i-1].x + dr[lo][i-1], a[i+1].x-a[i].x + st[i+1][hi]));
}
}
void solve()
{
for (int i = 1; i <= n; i++)
st[i][i] = dr[i][i] = a[i].y;
for (int i = 2; i <= n; i++)
for (int j = 1; j+i-1 <= n; j++)
update(j, j+i-1);
int rez = 0x3f3f3f3f;
for (int i = 1; i <= n; i++)
rez = min(rez, abs(a[i].x)+a[i].y*2 + max(a[i].x-a[i-1].x+dr[1][i-1], a[i+1].x-a[i].x+st[i+1][n]));
printf("%d", rez);
}
int main()
{
freopen("wanted.in", "r", stdin);
freopen("wanted.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d %d", &a[i].x, &a[i].y);
sort(a+1, a+n+1, coord());
solve();
return 0;
}