Pagini recente » Cod sursa (job #2891361) | Cod sursa (job #2776601) | Cod sursa (job #2222722) | Cod sursa (job #2974626) | Cod sursa (job #2712143)
#include <bits/stdc++.h>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
struct oras
{
int d;
int l;
};
bool cmp(oras A,oras B)
{
if (A.d != B.d)
return A.d < B.d;
else
return A.l > B.l;
}
int main()
{
int n,m,i,s,smax = 0;
vector<oras>a;
oras x;
in >> m >> n;
for (i = 1; i <= n; i++)
{
in >> x.d >> x.l;
a.push_back(x);
}
sort(a.begin(),a.end(),cmp);
int j = 1;
i = 0;
while (n > 1)
{
s = a[j].l + a[i].l + a[j].d - a[i].d;
if (s > smax)
smax = s;
if (a[j].l >= a[i].l + a[j].d - a[i].d)
{
//a.erase(a.begin());
n--;
i = j + 1;
swap(i,j);
}
else
{
//a.erase(a.begin() + 1);
n--;
j++;
}
}
out << smax;
return 0;
}