Pagini recente » Cod sursa (job #2188623) | Cod sursa (job #839338) | Cod sursa (job #1667711) | Cod sursa (job #3277720) | Cod sursa (job #2704169)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
struct carnaciori{
int time,price;
}v[2005];
bool cmp(carnaciori a,carnaciori b){
if(a.time<=b.time)
return true;
return false;
}
int main()
{
int i,n,sellerPrice,totalMax=0,currentIncome=0,currentPrice,waitingTime=0,added;
fin>>n>>sellerPrice;
for(i=1;i<=n;i++){
fin>>v[i].time>>v[i].price;
}
sort(v+1,v+n+1,cmp);
for(int k=1;k<=n;k++){
currentPrice=v[k].price;
currentIncome=0;
waitingTime=v[1].time;
added=0;
for(i=1;i<=n;i++){
if(currentPrice<=v[i].price){
currentIncome+=currentPrice;
added=1;
}
if(currentIncome-(v[i].time-waitingTime)*sellerPrice<=0){
if(added==1){
currentIncome-=currentPrice;
added=0;
}
if(currentIncome>totalMax)
totalMax=currentIncome;
currentIncome=0;
waitingTime=v[i+1].time;
}
else{
currentIncome-=(v[i].time-waitingTime)*sellerPrice;
waitingTime=v[i].time;
}
if(currentIncome>totalMax)
totalMax=currentIncome;
}
}
fout<<totalMax-sellerPrice<<endl;
return 0;
}