Cod sursa(job #3370823)

Utilizator Alex_Bita2Alexandru Alex_Bita2 Data 27 octombrie 2026 13:11:29
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
using namespace std;

ifstream f("branza.in");
ofstream g("branza.out");

const int Nmax = 100001;
long long lim = 100000000000014;
int p[Nmax], c[Nmax], n, s, t, stv[Nmax], dr, st;
long long sum, x, mn;

int main()
{
    f>>n>>s>>t;
    st = 1;
    
    for(int i=1; i<=n; i++)
    f>>c[i]>>p[i];
    
    for(int i=1; i<=n; i++){
        mn = lim;
        
        while(dr != st && c[i]<c[stv[dr]])
            dr--;
        
        stv[++dr] = i;
        
        if(i-stv[st] > t)
        st++;
        
        for(int j=st; j<=dr; j++){
            x = c[j]*1ll*p[i]+(i-stv[j])*1ll*s*p[i];
            
            if(x < mn)
                mn = x;
            
        }
        
        sum += mn;
    }
    
    g<<sum;

    return 0;
}