Cod sursa(job #2310159)
| Utilizator | Data | 30 decembrie 2018 17:58:07 | |
|---|---|---|---|
| Problema | Carnati | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.76 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream fin("carnati.in");
ofstream fout("carnati.out");
long n,c,t[2000],p[2000],i,pmax=0,G,news,old,j;
fin>>n>>c;
for (i=0; i<n; i++)
fin>>t[i]>>p[i];
for(i=0; i<n; i++)
{
old=0;
//news=p[i]-c;
//if(news>pmax)
// pmax=news;
//old=news;
for(j=0;j<n;j++)
{
if(p[j]>=p[i])
G=p[i];
else
G=0;
news=old-(t[j]-((j==0)?0:(t[j-1])))*c+G;
if(news<G-c) news=G-c;
if(news>pmax)
pmax=news;
old=news;
}
}
fout<<pmax;
fin.close();
fout.close();
return 0;
}
