Pagini recente » Cod sursa (job #406955) | Cod sursa (job #2609757) | Cod sursa (job #1170970) | Cod sursa (job #2791433) | Cod sursa (job #2712098)
#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()
{
ios_base::sync_with_stdio(false);
in.tie(NULL);
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);
/*
for (i = 1; i < n; i++)
{
if (a[i].d == a[i - 1].d and a[i].l > a[i - 1].l)
{
s = a[i].l + a[i - 1].l;
if (s > smax)
smax = s;
a.erase(a.begin() + i);
i--;
n--;
}
else if (a[i].d == a[i - 1].d)
{
s = a[i].l + a[i - 1].l;
if (s > smax)
smax = s;
a.erase(a.begin() + i);
i--;
n--;
}
}
i = 1;
while (n > 1)
{
s = a[i].l + a[i - 1].l + a[i].d - a[i - 1].d;
if (s > smax)
smax = s;
if (a[i].l <= a[i - 1].l + a[i].d - a[i - 1].d)
{
a.erase(a.begin() + i);
n--;
}
else
{
a.erase(a.begin() + i - 1);
n--;
}
}
*/
while (n > 1)
{
s = a[1].l + a[0].l + a[1].d - a[0].d;
if (s > smax)
smax = s;
if (a[1].l >= a[0].l + a[1].d - a[0].d)
{
a.erase(a.begin());
n--;
}
else
{
a.erase(a.begin() + 1);
n--;
}
}
out << smax;
return 0;
}