Cod sursa(job #2265048)

Utilizator buhaidarius@gmail.comBuhai Darius [email protected] Data 20 octombrie 2018 15:51:38
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
//
//  main.cpp
//  Branza
//
//  Created by Darius Buhai on 20/10/2018.
//  Copyright © 2018 Darius Buhai. All rights reserved.
//

#include <iostream>
#include <deque>
#include <fstream>

using namespace std;

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

int n, t, s, ct;
struct sapt{
    int c, p, i;
};
deque<sapt> b;

void rez_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();
    }
    //cout<<ct;
    fout<<ct;
}

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