Cod sursa(job #1939505)

Utilizator LeVladzCiuperceanu Vlad LeVladz Data 25 martie 2017 19:31:32
Problema Branza Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

int n,s,t,i,sol;
int d[100002];
int p,u;
pair <int, int> c[100002];

int main()
{
    fin >> n >> s >> t;
    for (i=1; i<=n; i++)
        fin >> c[i].first >> c[i].second;
    sort (c+1, c+n+1);
    d[1] = 1;
    p = 1;
    u = 1;
    sol += c[1].first*c[1].second;
    for (i=2; i<=n; i++)
    {
        while (p <= u && c[i].first <= c[d[u]].first+s*(i-d[u]))
            u--;
        d[++u] = i;
        if (i-d[p] == t+1)
            p++;
        sol += (c[d[p]].first+(i-d[p])*s)*c[i].second;
    }
    fout << sol;
    return 0;
}