Cod sursa(job #2775463)

Utilizator IoanaLiviaPopescu15Ioana Livia IoanaLiviaPopescu15 Data 15 septembrie 2021 20:58:52
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int main() {
    int n = 5, taxa = 10, termen = 3, pret, kg, best = 0, cost = 0, indice = 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(best_value + taxa * (i-best) > pret){
            best_value = pret;
            best = indice;
        }
        if(i-best == termen){
            best_value = pret;
            best = indice;
        }
        cost += kg * best_value + taxa * (indice-best) * kg;
        indice += 1;
    }
    g<<cost;
    return 0;
}