Cod sursa(job #117861)

Utilizator alexeiIacob Radu alexei Data 22 decembrie 2007 14:56:30
Problema Branza Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb

#include<fstream>
#define DIM 100000
using namespace std;
int main()
{
     ifstream f("branza.in");
     ofstream g("branza.out");
    long long pret[DIM],cerere[DIM];
    
int n,t,s;   
 
    f>>n>>s>>t;
    for(int i=1; i<=n; i++)
     f>>pret[i]>>cerere[i];
    f.close();
     long long cost,costt=pret[1]*cerere[1],costnou;
    for(int i=n; i>1; i--){
     
     cost=pret[i]*cerere[i];
       for(int j=i-1; j>=1&&j>=i-t; j--){
        costnou=pret[j]*cerere[i]+s*cerere[i]*(i-j);
         if(cost>costnou)
         cost=costnou;
         }
         
      costt+=cost;
      }  
 g<<costt;
    g.close();
    return 0;
}