Cod sursa(job #1801537)

Utilizator TimitocArdelean Andrei Timotei Timitoc Data 9 noiembrie 2016 09:49:08
Problema Branza Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <cstdio>
#define MAXN 100050

using namespace std;

int deck[MAXN], st, dr;
int n, s, t, c[MAXN], p[MAXN];
long long rez;

void read()
{
    scanf("%d %d %d", &n, &s, &t);
    for (int i = 1; i <= n; i++)
        scanf("%d %d", &c[i], &p[i]);

}

long long cost(int when, int now)
{
    return (1LL*s)*(now-when) + c[when];
}

void solve()
{
    st = 1, dr = 0;
    for (int i = 1; i <= n; i++) {
        while (st <= dr && cost(i, i) < cost(deck[dr], i))
            dr--;
        deck[++dr] = i;
        while (i-deck[st] > t)
            st++;
        rez += cost(deck[st], i)*p[i];
    }
    printf("%lld", rez);
}

int main()
{
    freopen("branza.in", "r", stdin);
    freopen("branza.out", "w", stdout);

    read();
    solve();

    return 0;
}