Pagini recente » Cod sursa (job #1245634) | Cod sursa (job #1877926) | Cod sursa (job #643233) | Cod sursa (job #957231) | Cod sursa (job #1061436)
#include <fstream>
#include <deque>
#define in "branza.in"
#define out "branza.out"
#define Max_Size 100100
#define LL long long
std :: ifstream f(in);
std :: ofstream g(out);
LL N, S, T;
LL V[Max_Size];
LL rez;
std :: deque < LL > DQ;
int main()
{
f >> N >> S >> T;
LL cost, cant;
for(LL i = 1;i <= N; ++i)
{
f >> cost >> cant;
V[i] = cost - i * S;
while(!DQ.empty() && V[DQ.back()] >= V[i]) DQ.pop_back();
DQ.push_back(i);
rez += cant * (V[DQ.front()] + i * S);
if(DQ.front() + T == i) DQ.pop_front();
}
g << rez << '\n';
g.close();
return 0;
}