Cod sursa(job #2265145)

Utilizator buhaidarius@gmail.comBuhai Darius [email protected] Data 20 octombrie 2018 17:10:39
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 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");

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

void rez_branza()
{
    
    fin>>n>>s>>t;
    for(long i=0;i<n;i++)
    {
        sapt 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);
        ct += (b.front().c+(i-b.front().i)*s)*ns.p;
        if(!b.empty() && i-b.front().i>=t)
            b.pop_front();
    }
    fout<<ct;
}

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