Pagini recente » Cod sursa (job #1831460) | Statistici Epure Iulian (Iuliep21) | Cod sursa (job #342006) | Cod sursa (job #164998) | Cod sursa (job #629141)
Cod sursa(job #629141)
#include <iostream>
#include <fstream>
#include <string>
# include <cstdlib>
#include <algorithm>
using namespace std;
ifstream in("carnati.in");
ofstream out("carnati.out");
int clienti;
int paguba;
pair <int,int> v[2001];
int profit(int pret)
{
int sc,smax,prc;
sc=smax=0;
for (int i =1;i<=clienti;i++)
{
if(v[i].second>=pret)
prc=pret-paguba;
else prc = -paguba;
sc= max(sc - (v[i].first-v[i-1].first-1)*paguba,0) +prc;
if (sc>smax) smax =sc;
}
return smax;
}
int main()
{
int hellYeha=0;
int imholding;
string tmp;
in>>tmp;
clienti = atoi(tmp.c_str());
in>>tmp;
paguba = atoi(tmp.c_str());
for (int i=1; i<=clienti ;i++ )
{
in>>tmp;
v[i].first = atoi(tmp.c_str());
in>>tmp;
v[i].second = atoi(tmp.c_str());
}
sort(&v[1],&v[clienti+1]);
v[0].first = -1000;
for (int i=0; i<clienti ;i++ )
{
imholding = profit(v[i].second);
if (imholding > hellYeha)
hellYeha = imholding;
}
out<<hellYeha;
}