Cod sursa(job #2411988)

Utilizator bluestorm57Vasile T bluestorm57 Data 21 aprilie 2019 15:21:27
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>

using namespace std;

ifstream f("branza.in");
ofstream g("branza.out");

const int inf = (1 << 30);
const int Nmax = 100005;
int v[Nmax], best[Nmax];
int cant, cost[Nmax];
long long int suma;
int n,s,t;
int last;
int value;

int main(){
    int i,j;
    f >> n >> s >> t;
    last = 1;
    for(i = 1; i <= n ; i++){
        f >> cost[i] >> cant;
        best[i] = inf;
        for(j = last ; j <= i ; j++){
            value = cost[j] * cant + (i - j) * cant * s;
            if(value < best[i])
                best[i] = value, last = j;
        }

        if(i - last == t )
            last++;
    }

    for(i = 1 ; i <= n ; i++)
       suma += best[i];


    g << suma;
    return 0;
}