Cod sursa(job #3126717)

Utilizator HaiduculAndrei Popa Haiducul Data 6 mai 2023 21:50:24
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
long long Zile,P,T;
long long suma,cantitate;
deque <int> deq;

int main()
{   long long pret[Zile+1];
    f>>Zile>>P>>T;
    for (int i=1; i <= Zile; ++i)
    {   f>> pret[i] >> cantitate;
        while(deq.size() > 0 and deq.front() < i-T){
            deq.pop_front();
        }
        while(deq.size() > 0 && ((i-deq.back()) * P + pret[deq.back()]) > pret[i]){
            deq.pop_back();
        }
        deq.push_back(i);
        suma += cantitate * (pret[deq.front()] + P * (i - deq.front()));
    }
    g<<suma;

    f.close(); g.close();
    return 0;
}