Cod sursa(job #2775468)

Utilizator IoanaLiviaPopescu15Ioana Livia IoanaLiviaPopescu15 Data 15 septembrie 2021 21:56:13
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int main() {
    long long n = 5, taxa = 10, termen = 3, pret, kg, best = 0, cost = 0, best_value;
    f>>n>>taxa>>termen;

    f>>pret>>kg;

    cost = pret * kg;
    best_value = pret;
    for(int i = 1; i < n; ++i){
        f>>pret>>kg;

        if(i-best >= termen){
            best_value = pret;
            best = i;
        }
        if(best_value + taxa * (i-best) > pret && best != i){
            best_value = pret;
            best = i;
        }


        cost += kg * best_value + taxa * (i-best) * kg;
    }
    g<<cost;

    return 0;
}