Pagini recente » Cod sursa (job #3291070) | Cod sursa (job #3141145) | Cod sursa (job #3286122) | Cod sursa (job #3263995) | Cod sursa (job #3247254)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
struct cel
{
int pret,timp;
}v[2001];
int cmp(cel a,cel b)
{
if( a.timp != b.timp )
return a.timp<b.timp;
return a.pret<b.pret;
}
int main()
{
int n, t, i, j, poz, maxx=-1;
f >> n >> t;
for( i=1; i <=n ; i++ )
f >> v[i].timp >> v[i].pret;
sort(v+1, v+n+1, cmp);
for( i=1; i <= n; i++ )
{
int p = v[i].pret;
int s = 0;
for( j=1; j <= n; j++ )
{
if( v[j].pret >= p )
{
poz = v[j].timp - 1;
break;
}
}
for( j=1; j <= n; j++ )
{
if( p <= v[j].pret )
{
if( p - t >= s + p - (v[j].timp - poz)*t )
s = p - t;
else s += p - (v[j].timp - poz)*t;
poz = v[j].timp;
if( maxx < s)
maxx=s;
}
}
}
g<<maxx;
return 0;
}