Pagini recente » Cod sursa (job #212913) | Cod sursa (job #1034935) | Cod sursa (job #1263487) | uvs_runda_1 | Cod sursa (job #1525482)
#include <iostream>
#include <fstream>
#define MAX_N 100001
using namespace std;
int d[MAX_N],first,last;
long C[MAX_N],P[MAX_N],n,t;
long long total;
int s;
void citeste()
{
ifstream f("branza.in");
f>>n>>s>>t;
for(int i=1;i<=n;i++)
f>>C[i]>>P[i];
f.close();
}
int main()
{
citeste();
first=1;
for(int i=1;i<=n;i++)
{
while(first<=last&&C[i]<C[d[last]]+(i-d[last])*s)last--;
d[++last]=i;
if(d[first]==i-t-1)first++;
total+=(C[d[first]]+(i-d[first])*s)*P[i];
}
ofstream g("branza.out");
g<<total;
g.close();
return 0;
}