Pagini recente » Cod sursa (job #405426) | Cod sursa (job #658638) | Cod sursa (job #2102228) | Cod sursa (job #1423748) | Cod sursa (job #2940680)
#include <fstream>
using namespace std;
ifstream in("carnati.in");
ofstream out("carnati.out");
struct client
{
int timp,bani;
}v[2001];
int main()
{
long long n,sg,sum=0,inc=1,profitulluigigel=-1,profitmax=-1,t,pmax=-1;
in>>n>>sg;
for(int i=1;i<=n;i++)
in>>v[i].timp>>v[i].bani;
for(int i=1;i<=n;i++)
{
sum=0;
inc=1;
profitmax=-10000000000;
for(int j=1;j<=n;j++)
{
if(sum<t*sg)
{
sum=0;
inc=j;
}
if(v[j].bani>v[i].bani)
sum+=v[i].bani;
t=v[j].timp-v[inc].timp+1;
profitulluigigel=sum-t*sg;
if(profitulluigigel>profitmax)
profitmax=profitulluigigel;
}
if(pmax<profitmax)
pmax=profitmax;
}
out<<pmax;
return 0;
}