Cod sursa(job #2889293)

Utilizator bigboiberkeBerke Musellim bigboiberke Data 12 aprilie 2022 16:13:26
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <deque>
#include <fstream>

using namespace std;

ifstream fin("branza.in");
ofstream fout("branza.out");

int n;
int t;
int s;
int ct;

struct saptamana{
    int c;
    int p;
    int i;
};

deque<saptamana> b;

void branza()
{

    fin>>n>>s>>t;
    for(int i=0;i<n;i++)
    {
        sapt ns;
        fin>>ns.c>>ns.p;
        ns.i = i;
        if(b.empty())
            ct+=ns.c*ns.p;
        else
        {
            int cc = ns.c*ns.p;
            for(auto it : b)
            {
                int ccc = it.c*ns.p + (i-it.i)*s*ns.p;
                if(ccc<cc)
                    cc = ccc;
            }
            ct+=cc;
        }
        b.push_back(ns);
        if(i-b.front().i>=t)
            b.pop_front();
    }
    fout<<ct;
}

int main() {
    branza();
    return 0;
}