Pagini recente » Cod sursa (job #2446072) | Cod sursa (job #1196157) | Cod sursa (job #873214) | Cod sursa (job #573479) | Cod sursa (job #1343163)
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream cin("orase.in");
ofstream cout("orase.out");
typedef struct pc
{
int x, y;
} ;
int n, i, m, j, k, r, best;
pc a[50005];
bool cmp(const pc &a, const pc &b)
{
return a.x<b.x;
}
int main()
{
cin>>m>>n;
a[1].x=1;
for
(i=1; i<=n; ++i)
cin>>a[i].x>>a[i].y;
sort(a+1, a+n+1, cmp);
best=1;
int sol=0;
for (i=3; i<=n; ++i)
if (a[i].x-a[best].x+a[i].y+a[best].y < a[i].x-a[i-1].x+a[i].y+a[i-1].y)
sol=a[i].x-a[i-1].x+a[i].y+a[i-1].y,
best=i-1;
else
sol=a[i].x-a[best].x+a[i].y+a[best].y;
cout<<sol;
return 0;
}