Cod sursa(job #2889314)

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

using namespace std;

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

int n;
int t;
int s;
long long 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++)
    {
        saptamana ns;
        ns.i = i;
        fin>>ns.c>>ns.p;

        while(!b.empty() && (b.back().c+(i-b.back().i)*s)>(ns.c))
            b.pop_back();
        b.push_back(ns);
            if(i-b.front().i>=t)
                b.pop_front();
        ct += (b.front().c+(i-b.front().i)*s)*ns.p;
    }
    fout<<ct;
}

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